CS50's Introduction to Programming with Python学习记录

Xiaozheng 于 2024-09-18 发布 浏览量

Problem Set 0

# Catch the user's input and make input lowercase
words = str(input()).lower()

# Print the result
print(words)
# Catch the user's input
text = input()

# Replace the space to "..."
new_text = text.replace(" ", "...")

# Print the result
print(new_text)
# Emoji Conversion
def convert(str):
    str = str.replace(":)", "🙂").replace(":(", "🙁")
    return str


def main():
    text = input()
    result = convert(text)
    print(result)


main()

import math

# Catch the user's input
m = int(input("m="))

# Calculate the fomular
E = m * pow(300000000, 2)

# Output the result
print(E)

def main():
    dollars = dollars_to_float(input("How much was the meal? "))
    percent = percent_to_float(input("What percentage would you like to tip? "))
    tip = dollars * percent
    print(f"Leave ${tip:.2f}")


def dollars_to_float(d):
    # TODO
    d = float(d.replace("$", ""))
    return d


def percent_to_float(p):
    # TODO
    p = float(p.replace("%", "")) * 0.01
    return p


main()

进行测试!