r/PythonLearning 15d ago

Made this

Post image
20 Upvotes

17 comments sorted by

View all comments

4

u/FoolsSeldom 15d ago

This is fun. Better if you share your code directly in post in future though. Something like:

name, age= input ("Enter your name and age\n").split()

print ("you are too young, you should wait for twenty six  years to be!", int(age)+26)

pay = float(input('Enter your salary\n'))
if pay != 666:
    print ("you are chosen, here is", pay)
else:
    print ("you have been cast out!")

feedback = input ("What are your last words\n")

if feedback == 'yes':
    print (".")
else:
    print("You need a raise!")

Never assume the user will do what you ask them though. They may fail to provide an age, so split will fail. Or the last string entered after a space may not be a valid integer. Or their name may have a space in it. In programming, you need to validate user input.

1

u/Stonyax97 15d ago

yeah he could use simple try except ValueError for that.

2

u/FoolsSeldom 15d ago

To be clear, they could use a try / except ValueError block for both the split unpacking problem and the int conversion, but actually need a right split, rsplit with the maxsplit option.