Python Forum
Unexpected output, not sure why
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unexpected output, not sure why
#1
I am a beginner and im trying to learn python for project with my brother.
Here is the code


 
""" so im learning python for a project with justin so i decided to see if i could remember what i learned so
far by making a this  little program. then i could show justin where im at and he can proceed with the project
accordingly. See attached text file for input/output table
"""

A="You're lying to me but lets continue"
B="Again with the lying... but lets keep going"

def lie1or2 (x):
    if x != "Justin" and x != "justin":
        return False
    if x == "Justin" and x == "justin":
        return True



print("So this is a little dealy I made to try and test what I learned so far and to see if it will run on "
      "your computer. Just fill in what it asks you.")
print("          ") #just to add a space

Name= input("What is your name?")

if Name != "Justin" and Name != "justin": #makes it so he can type in with OR without caps
    print(A) #your lying to me but lets continue
    Color= input("What is your favorite color?")

if Name == "Justin" and Name == "justin":         #answer was as expected continue collecting info
    Color = input("What is your favorite color?")


lie1or2(Name)  #calling function lie1or2 with input NAME i think?



if Color != "Orange" and Color != "orange": #why cant the first "color" be defined? Isnt it defined above?
    while lie1or2 is True:
        print(A)
        Favorite = input("Who is your favorite sibling?")
        break

if Color != "Orange" and Color != "orange":
    while lie1or2 is False:
        print(B)
        Favorite = input("Who is your favorite sibling?")
        break


Favorite = input("Who is your favorite sibling?")  #i shouldnt need this right? but it doesnt work without it.

if Color == "Orange" and Color == "orange":
    Favorite = input("Who is your favorite sibling?")

while Favorite != "Isaac" and Favorite != "isaac":
        print("Incorrect. Try again")
        Favorite = input("Who is your favorite sibling?") # this should loop until correct input. this is problem right?

while Favorite == "Isaac" and Favorite == "isaac":
    print("Correct!")
    print("           ")
    print("So your name is",Name,",your favorite color is",Color,",and your favorite sibling is",Favorite,"")
    print("      ")
    print("Please re-run this program using many different names, colors, etc. It shouldn't matter if it's capitalised "
          "or not because i made it that way.")
    break
and heres the input/output table of what it should do.



input "Name" output

Justin What is your favorite color?
justin what is your favorite color?
"anything else" your lying to me but lets continue
what is your favorite color?




input "Color" output

Orange who is your favorite sibling?
orange who is your favorite sibling?
"anything else if answered "Name" correctly your lying to me but lets continue
who is your favorite sibling?
"anything else if answered "Name" incorrectly again with the lying... but lets keep going'





input "Favorite" output

Isaac correct

So your name is "Name input" , your favorite color is "Color input" , and your favorite sibling is "Favorite input"

Please re-run this program using many different names, colors, etc. It shouldn't matter if it's capitalised or not because i made it that way


isaac correct

So your name is "Name input" , your favorite color is "Color input" , and your favorite sibling is "Favorite input"

Please re-run this program using many different names, colors, etc. It shouldn't matter if it's capitalised or not because i made it that way



"Anything else" Incorrect. Try again (this should repeat after each attempt until correct input, in which case it will then print the above lines)
Reply
#2
Quote:if Name != "Justin" and Name != "justin": #makes it so he can type in with OR without caps
print(A) #your lying to me but lets continue
Color= input("What is your favorite color?")

if Name == "Justin" and Name == "justin": #answer was as expected continue collecting info
Color = input("What is your favorite color?")
I think you meant or not and. Name cannot be both Justin and justin at the same time.

You can utilize python builtins and convert the input to lowercase, then you dont have to check for uppercase

if name.lower() == 'justin':
Then name could be justin, JUSTIN, Justin, etc.

Color is never defined because of the issue above. None of your if conditions are ever true because Name cannot be both Justin and justin. It however can not be both justin and Justin. If you put anything other than either of those, it runs through as you are saying "if not both". You want the or operator here, not and.

There is another package whois, that has versions for python 2 and 3, it also is old, but at least can be installed with pip

pip install whois
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected output Starter 2 439 Nov-22-2023, 12:08 AM
Last Post: Starter
  Unexpected Output - Python Dataframes: Filtering based on Overlapping Dates Xensor 5 654 Nov-15-2023, 06:54 PM
Last Post: deanhystad
  Unexpected output while using random.randint with def terickson2367 1 467 Oct-24-2023, 05:56 AM
Last Post: buran
  Unexpected output from df.loc when indexing by label idratherbecoding 6 1,125 Apr-19-2023, 12:11 AM
Last Post: deanhystad
  unexpected output asyrafcc99 0 1,478 Oct-24-2020, 02:40 PM
Last Post: asyrafcc99
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,011 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  Unexpected output palladium 4 2,695 Jan-11-2020, 03:26 PM
Last Post: palladium
  Unexpected output: if statement CabbageMan 1 1,728 Sep-04-2019, 04:12 PM
Last Post: ThomasL
  Unexpected Output using classes and inheritance langley 2 1,912 Jul-04-2019, 09:33 AM
Last Post: langley
  float multiplication - unexpected output inesk 3 3,253 Dec-11-2018, 10:59 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020