ThunderBear ThunderBear - 1 month ago 5
Python Question

Basic Python function

I am trying to complete two different questions but cannot get them to work. Please help me understand where I went wrong.


  1. For each number between 1 and 100, odds should be normal and even numbers should print out the word "Billy". Must start at 1 not 0 and include the number 100. Here's my answer (I know I'm way off):



for i in range(1,101):

if i % 2 == 0:
print(Billy)

else:

print(i)


  1. Ask the user: "What is your name?". Response should look like "Hello Billy" for all names except Joe and Susie. For Joe it should say "Hi Joe :)" and for susie it should say "Ahoy Susie :D". Here is where I'm at:



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

if name == "Joe":
print("Hi Joe :)")

if name == "Susie":
print("Ahoy Susie :D)

else: print("Hello", name)

Thanks for your help!

Answer

try this

for i in range(1,101):

    if i % 2 == 0:
       print('Billy') #you missed quote marks here

    else:
       print(i)

(bad indentation, and missing quote marks)

and

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

if name == "Joe":
    print("Hi Joe :)")

elif name == "Susie":
    print("Ahoy Susie :D") #and you missed quote marks here

else: 
   print("Hello" + name)

...same issues.

Comments