I just started learning computer science in general and Python language in particular. So I do not have many experiences with it. There is a problem that it takes me too much source code to complete. Do you guys know any shorter way to complete this? The problem is attached below. Please help me. Thank you so much, red blue white requirements
CodePudding user response:
Here's some very basic code I wrote for you as an example. (note that in this example I prompt a user for a number between 0 and 30 but there is no logic to test this; please adapt this code to however your instructor wants):
choice = int(input('Choose a number between 0 and 30: '))
if choice < 10:
print('RED')
elif 10 <= choice <= 19:
print('WHITE')
elif choice > 20:
print('BLUE')
Run it through your IDE and let me know if you have any questions about it! (also, this code could be simplified in many ways, but you should play around with that)
CodePudding user response:
I'm providing the basic solution. You can refer to it and make changes according to your problem statement. You need to focus on your basics.
inputNumber = int(input("Enter the number"))
if inputNumber >= 20:
print("Blue")
elif inputNumber < 10:
print("Red")
else:
print("White")