boatofturtles
boatofturtles

Reputation: 125

Python 3.2.0 using def

Hi I was making a script y'now, just for fun and I came across a small problem.

The way my code needs to work, I need to recall a script but to do that it needs to be recalled in a recall of another script.

I know kinda confusing but it makes a little more sense in the script. Here's my code:

 # Importing time and date... 
 import time 
 import datetime

 # Defining ans() and name(). 
 def ans():
     print("Are you sure your name is Vegas?")
     time.sleep(2)
     print("Well I'm not so sure.")
     time.sleep(1)
     print("You'll have to prove it.")
     time.sleep(1)
     print("Which typewriter brand does Vegas have?")
     print("1. Sizzix")
     print("2. Royal")
     print("3. Alivetti")
     print("4. Smith-Corona")
     ans=input(">")
     if ans == "4":
         print("Correct....")
     else:
         print("Incorrect! You are not Vegas! Liar!")
         name() 

 def name():
     name=0
     print("Detecting...")
     time.sleep(2)
     name == input("Is your name Vegas? (Y or N) >")
     if name == "Y":
         ans()
     if name == "N":
         name()

 # Now for the actual script. This prints the time and then runs the code in name(). 
 now = datetime.datetime.now() 
 print(now, " --That is the time.") 
 name()
 # If name == Y, then it's supposed to go to ans() and run the code there.
 # Instead it goes through the code inside name() and then stops.

All the big font is just stuff I used as notes (#). I was making this script for my friend whose name is Vegas so that explains that.

Upvotes: 0

Views: 69

Answers (3)

lahmbi5678
lahmbi5678

Reputation: 11

name == input("Is your name Vegas? (Y or N) >")

is probably wrong, what you want is

name = input(...)

Upvotes: 1

Xiaowei Liu
Xiaowei Liu

Reputation: 89

Two Errors:
1. NOTE THE ASSIGNMENT SYMBOL.
name = input("Is your name Vegas? (Y or N) >")
instead of
name == input("Is your name Vegas? (Y or N) >")

2.Bad name of variable
In method "name()", change the name of the variable("name") which is assigned to the return value of input():
nameVar = input("Is your name Vegas? (Y or N) >")
If we don't do this, we will get the ERROR:
TypeError: 'str' object is not callable
I think you've already know why this happens(Name conflict between variable name and method name)!

Upvotes: 1

user4414248
user4414248

Reputation:

name == input("Is your name Vegas? (Y or N) >")

Problem is here. It should be;

name = input("Is your name Vegas? (Y or N) >")

This, your input is wrong so actually your input is always False, that's why your function is never processing.

Upvotes: 0

Related Questions