How do I get this to work | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I get this to work

If I want the input to be between 1 and 10 and the input is placed higher than 10 how do I make it send a different message to what is will be if it is between 1 and 10

15th Mar 2024, 3:59 PM
Keagan Brendan
Keagan Brendan - avatar
4 Answers
+ 2
Another way is use: ipt = input() if len(ipt) != 1: #whith strings, len will return hoy many character does the string have(space is also a character) print("lol") The thing is, the user may input something that is not even a number, so you should put all this code in try: just like this try: # try makes that if de code inside will have an error, the program will not stop and the except code will run ipt = int(input()) (The rest of the code) except TypeError: print("please input a number")
15th Mar 2024, 4:16 PM
AiVolt
AiVolt - avatar
+ 2
This is a way. You could copy and paste this in the sololearn playground. ipt = int(input()) # input() always return a string, so you should use int() for making the input an integer if ipt >10: # this makes that if the input is bigger than 10 the code bellow will run print("please input a smaller number") # Be carefull whith the identation # And here goes the rest of the code
15th Mar 2024, 4:10 PM
AiVolt
AiVolt - avatar
+ 1
AiVolt I got it working here is the code if u want to look at idk #think of a number between 1 and 10 ipt = int(input()) if ipt >=11: print("Cant bamboozle this code, try again") if ipt <11: print("You were thinking of the number",ipt)
16th Mar 2024, 5:22 AM
Keagan Brendan
Keagan Brendan - avatar
0
You can achieve this with a simple conditional statement. Here's an example in Python: ```python number = int(input("Enter a number between 1 and 10: ")) if number >= 1 and number <= 10: print("The number is between 1 and 10.") else: print("The number is not between 1 and 10.") ``` This code prompts the user to enter a number. If the number entered is between 1 and 10 (inclusive), it prints "The number is between 1 and 10." Otherwise, it prints "The number is not between 1 and 10."
16th Mar 2024, 12:03 PM
Rohit Krishna
Rohit Krishna - avatar