Question

I am trying to write a simple program, where python counts the number of characters in your name and decdes how cool your name is. trying to learn if and elif statements... this is what I have so far

P.S. i am using python 2.7

def main():
    print"This program will tell who has a cooler name on a scale of 1-10"
    print""
    name=input("Enter your name: ")
    if len(name)<=4:
        print"on a scale of 1-10 your name is a 2! what a lame name..."
    elif (len(name)>4) and (len(name)<=7):
        print"That is a cool name you deserve a 8/10! Awesome!"
    elif len(name)>7:
        print"you are a 10/10, no one has a better name than you!"

main()
Was it helpful?

Solution

n = len(name)  # it might be wise to store this

if n <= 4:     # as you have already
    ...
elif n <= 7:   # you already know n > 4 here; no need to test for that
    ...
else:          # you already know n > 7 here; this should be else
    ...

Also, since you're using Python 2.7, you want raw_input() instead of input().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top