0
Please what's wrong with this code? I keeep getting User is not defined.
# It has been corrected num = list(range(1, 20)) User = int(input("enter a number:")) for i in num: if User % 3 ==0: print("You got it") break elif User > 20: print("Almost there") break else: print("Try again") break
24 ответов
+ 6
Check that print() is not capitalised?
I think all the python functions are lowercase or maybe camelCase.
I also see that you have used range(1,20)
That will give you a sequential list starting at 1 but finishing at 19. Is that what you wanted?
The range() function takes 3 arguments, start, end, step. So range(2,8,3) would give 2, 5 but would not give the next step of 3 because it exceeds or is equal to the end value.
+ 4
G'day David Michael or should I say dAVID mICHAEL....
Capitalisation matters to a lot of programming languages, python included.
your last print() statement is also incorrectly capitalised.
+ 4
Python is case sensitive:
"User" and "user" are two different variables;
Print() #bug
+ 2
Ooh, oh my God
I just found it, thank you very much.
I love this community
+ 2
No worries. Can you become a champion of the forum? Edit your original post to start with [Solved]
https://www.sololearn.com/discuss/1316935/?ref=app
+ 2
Yea, it is what I wanted, I was just trying it out, I'm new to all of these.
And I didn't really understand the range you explained, I think I'll check a video on it.
Thank you very much, this is relly helpful
+ 2
Sorry about jamming extra information in, I should have left it at helping you to find rogue capital letters. 👍
+ 2
HungryTradie If I don't break, it'll print the reult multiple times
+ 2
Korkunç TheTerrible It is to check a number between 1 to 20 that is divisible by 3
+ 2
David Michael So you don't want a for loop, then?
Why not just:
n = int(input())
if n<20 and n%3 ==0:
print("yay")
else:
print (n, "is not a multiple of 3 that is less than 20")
If you had no idea about the logic operator "and", you could do:
n = int(input())
if n % 3 ==0:
if n < 20:
print("yay")
else:
print("a mult of 3 less than 20 please")
else:
print(" the number you enter should be both a multiple of 3 and less than 20")
I mean I don’t know, but if you want to do it once, neither the list nor the for loop is for that purpose.
If you want to try all numbers within the list the breaks need to be removed.
BTW: I am a noob, I just got confused
+ 1
I still have a problem, if i input a number greater than 20, I get an error message that print name is not defined, what do i do?
+ 1
Hungry Tradie
Thank you very much, I just corrected that.
+ 1
No, you just gave me somethinn to learn today, am I'm on it now.
Thank you, My account is not verified yet, I would've inbox
+ 1
HungryTradie I think there's a problem with that somehow,
+ 1
https://code.sololearn.com/cX26Wavg1zfE/?ref=app
HungryTradie This is my modification
+ 1
Ok, I'm sorry, but I don't understand the game.
You have each option terminated by a break, so your for loop won't get another iteration. Don't you want one of them to continue the loop?
Your success condition is always any multiple of 3, disregarding not more than 20.
If it is how you want it, then that is great. Well done.
+ 1
You don't need to use loop then
num = list(range(1, 20))
User = int(input("enter a number:"))
if ():
print()
elif ():
print()
else:
print()
+ 1
I am a learner too. May I ask what the purpose of this code is? It looks confusing to me.
+ 1
There are no error in this code.
You could wrote it wrong in case means upper or lower.
+ 1
Yeah just like the first comment, I think you capitalized the variables wrongly in the print()