I need help with python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

I need help with python

I have to do a dice game for course work at school (in python) and using the knowledge of this app i put together the log in section of the game l, but i am unable to find the errors myself, so i was wondering if anyone could help me please. The problem is when i execute the code it allows any username and password to log in. https://code.sololearn.com/cWqDiTY8xddH/?ref=app

19th Oct 2019, 2:23 PM
Mponec
Mponec - avatar
6 Answers
+ 4
if str == 'a' or 'b': is evaluated as if (str == 'a') or ('b'): which will always be true. Instead, do if str == 'a' or str == 'b': In the case of your code, change all if statements according to the above fix. if userinpuse == 'player1' or userinpuse == 'player2': etc.
19th Oct 2019, 2:40 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Mponec For assignments, use =, and not ==. username = str(input('Username: ')) etc.
19th Oct 2019, 2:56 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Hello Mponec I see your code is quite big, that's why it didn't fit in Description section. Would you mind saving the code in your profile and share its link instead? remove the code text and put the code link in place of it 👍 Here's how to share links just in case you didn't know yet. https://www.sololearn.com/post/74857/?ref=app
19th Oct 2019, 2:31 PM
Ipang
+ 2
userinpus == str('player1') are actually get executed first. then or comes in after the input. so for example userinpus is 'player' userinpus == str('player1') or str('player2') 'player' == 'player1' or 'player2' false or 'player2' 'player2'
19th Oct 2019, 2:38 PM
Taste
Taste - avatar
+ 1
Mponec I see you saved the code and share its link. Thank you for understanding 👍
19th Oct 2019, 3:14 PM
Ipang
0
Now i am getting no output displayed but it still asks for my inputs, altogh it did say check internet connectin but i have full bars
19th Oct 2019, 3:02 PM
Mponec
Mponec - avatar