QuestionPython Cancel Print

Posts 13 of 3 · Page 1 of 1
Python Cancel Print
Hello, I just started messing around with Python today and was kind of confused on how to make this code not print "You may pass, " when input "Peter" is entered by the user. When the input "Peter" is used it prints what I would like it to "You shall die, Peter" but I would like it to only print that and not "You may pass," as well.

Example 1:

Halt!
Who goes there? Random Name
You may pass, Random Name

Example 2:

Halt!
Who goes there? Peter
You may pass, Peter
You shall die, Peter

The Code ↓

print("Halt!")
user_input = input("Who goes there? ")
print("You may pass,", user_input)

if user_input == "Peter":
print("You shall die,", user_input)

else: print
Code:
print("Halt!")
user_input = input("Who goes there? ")


if user_input == "Peter":
    print("You shall die,", user_input)

else:
    print("You may pass,", user_input)
It will check if Peter is entered and if so prints "You shall die." otherwise anything else it prints "You may pass.".



Best regards.
Thanks for the help CwDirectly.
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?