CS50P Problem Set 0 Solution

Here is the solution to CS50’s Introduction to Programming with Python Week 0.

Indoor voice

x = input("Please Enter your Phrase to lowercase:")
print(x.lower())

Playback Speed

x = input("Please Enter Your Text: ")
print(x.replace(" ","..."))

Making Faces

def main():
    msg = input("Please Enter: ")
    result = convert(msg)
    print(result)
def convert(msg):
    msg1=msg.replace(":)","????")
    msg2=msg1.replace(":(","????")
    return msg2
if __name__ == "__main__":
    main()

Einstein

def main():
    m = int(input("Please Enter Mass: "))
    print(f"E={energy(m)}")
def energy(mass):
    C = 300000000
    E = mass*C*C
    return E

if __name__=="__main__":
    main()


Tip Calculator

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):
    return float(d.strip("$"))

def percent_to_float(p):
    return float(p.strip("%"))/100

main()

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.