+ 1
What can I do to reset the 'urun' variable? (python)
- I entered correctly all the variables - while True: urun = str(input("Enter a letter (a - c): ")) if urun == 'a': print(x) elif urun == 'b': print(y) elif urun == 'c' : print(z) else: print(enter a valid letter)
6 Answers
+ 1
Is that full code? It reset urun in every iterstion by input.
What are x, y, z variable?
+ 1
#Yusuf Kayra Bucak
x,y,z = 35,80,5
while True:
urun = input("Enter a letter (a - c): ")
if urun == 'a':
print(x)
elif urun == 'b':
print(y)
elif urun == 'c' :
print(z)
else:
print("enter a valid letter")
break
"""
input :
a
b
c
d
output i got :
Enter a letter (a - c): 35
Enter a letter (a - c): 80
Enter a letter (a - c): 5
Enter a letter (a - c): enter a valid letter
"""
+ 1
Yusuf Kayra Bucak Are you sure you are using this same code?
May be you are using =, instead of ==, in urun == 'a'? Or taking input before loop?
Do check it clearly.....
0
You can set it to an empty string.
urun = ""
Though I don't think it's necessary to reset it since it will be set when read a new input at the beginning of each iteration.
Side note, no need to wrap input() in str() since it already returns a str.
0
That's the problem, it doesn't reset each iteration. Also, regardless of what I enter as input, its output is always x (What my first input was a when I first made this.)
Jayakrishna🇮🇳 x is 35, y is 80, z is 5. The first part is setting these variables, and I wrote the second part, nothing comes after that.
Mozzy urun = "" doesn't work. Also, it was giving an error when the input() was not wrapped in str() 🤔
Idk if it's cuz of pycharm
0
What can be causing it to return x everytime? Jayakrishna🇮🇳 (I simplified the code but it's base is like that, the simplfication is making a long printed string into only x etc)