Python Forum
Check if integer is between two values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Check if integer is between two values
#1
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
Reply


Messages In This Thread
Check if integer is between two values - by Wolfpack2605 - Dec-24-2017, 12:47 AM
RE: Check if integer is between two values - by mpd - Dec-24-2017, 01:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Iterating over pandas.df to check for values out of range Padowan 14 12,585 Nov-26-2017, 04:37 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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