zer0space
zer0space

Reputation: 3

How do I use % in python 3

I have a python code written in 2.7 and i would have to upgrade it to python 3 how do i go about the syntax difference raw_input and at %

n=[]

print('Welcome to Rock-Paper-Scissors')

gamenum = int(input("How many games of Rock-Paper-Scissors you want to play?"))
while  (gamenum % 2 == 0):
        gamenum = int(input("Please enter an odd number of games:"))
else:
        n.insert(0, range (1,gamenum+1))


computer = ''
for i in range(gamenum):
  player = raw_input('Game %d\nYou can pick\n' % (i + 1))
  if player == computer:
        print("Tie!")
  elif (player == "R"):
        computer = 'Paper'# == "Paper"
        print('The computer picked') , computer, ('You lose.')
  elif (player == "P"):
        computer = 'Scissors'# == "Scissors"
        print('The computer picked') , computer, ('You lose.')
  elif (player == "S"):
        computer = 'Rock'# == "Rock"
        print('The computer picked') , computer, ('You lose.')

Upvotes: 0

Views: 74

Answers (1)

Sebastiaan
Sebastiaan

Reputation: 1276

Have a look at the str.format() functionality in python 3. Application-wise the jist is that '%d is a number' % 5 is replaced complemented by '{} is a number'.format(5), but there is actually much more. You can supply keyword arguments, formatting conditions and even make method calls with the {} syntax.

So

'Game %d\nYou can pick\n' % (i + 1))

Would become anything between

'Game {}\nYou can pick\n'.format(i + 1)

and

'Game {number:0^3d}\nYou can pick\n'.format(number=i + 1)

Upvotes: 1

Related Questions