Python If Statement

I am making a text Russian game of roulette in Python, but I almost did not finish, as you can see, just by looking at my code:

#!/usr/bin/env python print("The maximum number of bullets is 3") bulletcounter = input("How many bullets do you want your gun to have?") print(bulletcounter, "bullets") paname = input("Enter Player 1 Name: ") pbname = input("Enter Player 2 Name: ") print(paname.capitalize(), "Vs.", pbname.capitalize()) if bulletcounter == 1: bulletcount = 0 print(bulletcount) bulletaloc = random.randint(1, 6) while bulletaloc != bulletcount: bulletcount += 1 

For some reason, even if someone enters 1 into a bulletcounter, it does not run the if statement "if bulletcounter == 1". How to make it run if-statment

+4
source share
1 answer

Use raw_input for your paname and pbname . Make sure import random is at the top of the file. It would be better to use int(raw_input("How many...")) for bulletcounter too, I think, than input , since it can be used to evaluate any arbitrary python code.

It's also worth checking out which version of Python you are using when you invoke it with the env command. If on the command line you run:

 /usr/bin/env python -V 

and get "Python 2.xy" instead of Python 3, and you expect to use Python 3, consider changing this first line to use the Python 3 interpreter instead. The above recommendations assume that you are using Python 2.

+4
source

Source: https://habr.com/ru/post/1399909/


All Articles