Dec-24-2017, 12:47 AM
Hi,
I am quite new to Python and I am having trouble with solving a problem with an online course I am undertaking on Grok Learning. This is the question
Write a program that checks how long a name is. The program should take a name as input from the user.
If the name has 3 or fewer letters, your program should work like this:
Enter your name: Lin
Hi Lin, you have a short name.
If the name has between 4 and 8 letters (inclusive), your program should work like this:
Enter your name: Jimmy
Hi Jimmy, nice to meet you.
Otherwise, if the name has more than 8 letters, your program should work like this:
Enter your name: Yaasmeena
Hi Yaasmeena, you have a long name.
This is what I have done:
name=input("Enter your name: ")
x=(len(name))
if x<=3:
print("Hi", name+",", "you have a short name.")
if x>=8:
print("Hi", name+",", "you have a long name.")
else:
print("Hi",name+",","nice to meet you.")
The problem I am having is when a name with a length of 3 or less is entered, the out put is:
Enter your name: JP
Hi JP, you have a short name.
Hi JP, nice to meet you.
when it was meant to output:
Enter your name: JP
Hi JP, you have a short name.
I need a way to differentiate between the lengths.
Please help. thanks
I am quite new to Python and I am having trouble with solving a problem with an online course I am undertaking on Grok Learning. This is the question
Write a program that checks how long a name is. The program should take a name as input from the user.
If the name has 3 or fewer letters, your program should work like this:
Enter your name: Lin
Hi Lin, you have a short name.
If the name has between 4 and 8 letters (inclusive), your program should work like this:
Enter your name: Jimmy
Hi Jimmy, nice to meet you.
Otherwise, if the name has more than 8 letters, your program should work like this:
Enter your name: Yaasmeena
Hi Yaasmeena, you have a long name.
This is what I have done:
name=input("Enter your name: ")
x=(len(name))
if x<=3:
print("Hi", name+",", "you have a short name.")
if x>=8:
print("Hi", name+",", "you have a long name.")
else:
print("Hi",name+",","nice to meet you.")
The problem I am having is when a name with a length of 3 or less is entered, the out put is:
Enter your name: JP
Hi JP, you have a short name.
Hi JP, nice to meet you.
when it was meant to output:
Enter your name: JP
Hi JP, you have a short name.
I need a way to differentiate between the lengths.
Please help. thanks