-6
# Mit Print kann ich das Programm den Wert einer Variablen ausgeben/anzeigen lassen

print 'Please choose a number'    
a = raw_input(int)    
print 'Please choose a different number'    
b = raw_input(int)    
print 'Please again choose a different number'    
c = raw_input(int)   
print (a**b)/c

Why is this not working? I always get the error

TypeError: unsupported operand type(s) ** /: 'str' and 'str'

I thought the sign for exponate is **, so why this does not work?

olly_uk
  • 11,559
  • 3
  • 39
  • 45
Marcel Iseli
  • 11
  • 1
  • 3

5 Answers5

2

In your code, a, b and c are strings rather than integers.

Change

a = raw_input(int)    

to

a = int(raw_input())

etc.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
2

raw_input returns a string as detailed on the Python docs.

To do what you are trying you would have to first convert the string to an int like below :

a = int(raw_input())
olly_uk
  • 11,559
  • 3
  • 39
  • 45
0

Try this form for each input:

a = int(raw_input())    
dansalmo
  • 11,506
  • 5
  • 58
  • 53
0

Try this:

#     print 'Please choose a number'    
a = raw_input('Please choose a number' )    
#     print 'Please choose a different number'    
b = raw_input('Please choose a different number' )    
#     print 'Please again choose a different number'    
c = raw_input('Please again choose a different number')   
print (float(a)**float(b))/float (c)
Vivek
  • 910
  • 2
  • 9
  • 26
0

raw_input returns a string not an integer, besides its first argument is the prompt that appears before what the user types.

To parse a string into an integer use

the_string = raw_input()
the_integer = int(the_string)

Alternatively, test whether the string can be parsed into an integer

the_integer = None
while the_integer is None:
    print 'Please choose a number'
    the_string = raw_input()
    try:
        the_integer = int(the_string)
    except ValueError:
       print 'That was not a valid number'
OdraEncoded
  • 3,064
  • 3
  • 20
  • 31