+ 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)

14th Nov 2022, 8:44 AM
Yusuf Kayra Bucak
Yusuf Kayra Bucak - avatar
6 ответов
+ 1
Is that full code? It reset urun in every iterstion by input. What are x, y, z variable?
14th Nov 2022, 9:51 AM
Jayakrishna 🇮🇳
+ 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 """
14th Nov 2022, 10:26 AM
Jayakrishna 🇮🇳
+ 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.....
14th Nov 2022, 10:35 AM
Jayakrishna 🇮🇳
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.
14th Nov 2022, 9:55 AM
Mozzy
Mozzy - avatar
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
14th Nov 2022, 10:16 AM
Yusuf Kayra Bucak
Yusuf Kayra Bucak - avatar
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)
14th Nov 2022, 10:29 AM
Yusuf Kayra Bucak
Yusuf Kayra Bucak - avatar