# Can you ask for input inside a function?

I was working on :

While coding for the Roulette game, I wanted to ask the user for input from within a function.
This is what I wrote

`````` #roulette
#i is input.
#1 for even and odd
#2 for straightup
def roulette(i,b):
global m3
n = random.randint(0,40)
#even odd
if i==1:
i1 = int(input("1 for even, 2 for odd"))
if n%2==0 and i1==1:
m3+=b
s = "You won. Balance = \$",m3," ."
elif n%2!=0 and i1==2:
m3+=b
s = "You won. Balance = \$",m3," ."
else:
m3-=b
s = "You lost. Balance = \$",m3," ."
#straight up
elif i==2:
i2 = int(input("Enter number to bet upon"))
if n==i2:
m3+=b+35
s="Jackpot.Balance = \$",m3," ."
else :
m3-=b
s="You lost.Balance = \$",m3," ."
#Any other case
else:
s = "Please enter valid input."
return s,m3
``````

Traceback (most recent call last):
File â€śscript.pyâ€ť, line 92, in
print(roulette(1,40))
File â€śscript.pyâ€ť, line 68, in roulette
i1 = int(input(â€ś1 for even, 2 for oddâ€ť))
EOFError: EOF when reading a line

The entire project so far :

``````import random
money = 100

#coinflip
def coinflip(i,b):
global money
num = random.randint(1,2)
if i==num:
money += b
s = 'The outcome matched and you won \$ ',b,' .Your current balance is \$',money,' .'
else:
money -= b
s = "The outcome did not match and you lost \$ ",b," .Your current balance is \$",money," ."
return s,money
#coinflip call
print(coinflip(1,50))
m1 = money
print(m1)

#cho_han
#1 = even, 2 = odd
def cho_han(i,b):
global m1
num1 = random.randint(1,6)
num2 = random.randint(1,6)
if (num1+num2)%2 == 0 and i==1:
m1 += b
s = "Matched. Balance = \$",m1,"."
else:
m1 -= b
s = "Did not match. Balance = \$",m1,"."
return s,m1
#cho_han call
print(cho_han(1,20))
m2 = m1
print(m2)

#pack of cards
def cards(b):
global m2
p1 = random.randint(1,13)
p2 = random.randint(1,13)
#p1 is our guy
if p1>p2:
m2 += b
s = "You won. Balance = \$",m2," ."
elif p1<p2:
m2 -= b
s = "You lost. Balance = \$",m2," ."
else:
s = "Its a tie. Balance = \$",m2," ."
return s,m2
#cards call
print(cards(35))
m3 = m2
print(m3)

#roulette
#i is input.
#1 for even and odd
#2 for straightup
def roulette(i,b):
global m3
n = random.randint(0,40)
#even odd
if i==1:
i1 = int(input("1 for even, 2 for odd"))
if n%2==0 and i1==1:
m3+=b
s = "You won. Balance = \$",m3," ."
elif n%2!=0 and i1==2:
m3+=b
s = "You won. Balance = \$",m3," ."
else:
m3-=b
s = "You lost. Balance = \$",m3," ."
#straight up
elif i==2:
i2 = int(input("Enter number to bet upon"))
if n==i2:
m3+=b+35
s="Jackpot.Balance = \$",m3," ."
else :
m3-=b
s="You lost.Balance = \$",m3," ."
#Any other case
else:
s = "Please enter valid input."
return s,m3
#roulette call
print(roulette(1,40))

``````

Thanks

Not all codecademy lessons can handle `input()` function equally well. Running this code outside of codecademy goes fine:

https://repl.it/@stetim94/OverdueFalseDungbeetle

4 Likes

@msquaresproperty, for some reason the Codecademy interface for this lesson does not accept input(). See this thread for more.

4 Likes

Thanks man