Python Forum
Can someone fix this simple code so it works?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone fix this simple code so it works?
#1
I get a syntax error. Here is the code:
gender = raw_input("Whats your gender")
age = (int(raw_input("Whats your age")) 
if gender == female and age >= 18:
    print "good"
else: print "bad"
Reply
#2
You should show the error message.
Line 2 is missing closing ) and should be quote around 'female'.
The code is also Python 2.
gender = raw_input("Whats your gender: ")
age = int(raw_input("Whats your age: "))
if gender == 'female' and age >= 18:
    print "good"
else:
    print "bad"
You should of course use Python 3.6 -->,then it look like this.
gender = input("Whats your gender: ")
age = int(input("Whats your age"))
if gender == 'female' and age >= 18:
    print("good")
else:
    print("bad")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 291 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 965 Nov-15-2023, 06:56 PM
Last Post: jst
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 471 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Code works but doesn't give the right results colin_dent 2 709 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,427 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  help me simple code result min and max number abrahimusmaximus 2 901 Nov-12-2022, 07:52 AM
Last Post: buran
  Simple encoding code ebolisa 3 1,436 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,784 Feb-21-2022, 10:52 AM
Last Post: Gribouillis
  Pyspark - my code works but I want to make it better Kevin 1 1,773 Dec-01-2021, 05:04 AM
Last Post: Kevin
Question email code works in 2.7 but not in 3 micksulley 3 2,558 Nov-04-2021, 09:44 PM
Last Post: micksulley

Forum Jump:

User Panel Messages

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