Class challange

Hi I wanted to get some help on how I could solve this python problem as I am just a beginner in python.
allow the user to enter their school code and last names and will output their username in the school format (up to 5 letters from their lastname, or 4 if there are any spaces, followed by their school id number)

this is the code I have done so far:
person = input("Enter your last name: ")
school_ID = int(input("Enter your school number: "))
def count_chars(txt):
result = 0
for char in txt:
result += 1
return result
print(person, school_ID)

Any help in how I should move forward would be much appreciated.

1 Like

Hello @aaa242006, welcome to the forums! You need to try and break this down further. What is it that you want to accomplish in each step?

  1. You want to get their last name
  2. You want to get their school ID number.
  3. You want to see if their last name has any spaces.
  4. If it has spaces, you want to get the first 4 letters. Otherwise, you want to get the first (upto) 5.
  5. You want to put this together with their school number.

How many have you done with your current code? Well, you’ve done the first 2. Now, how would you accomplish the third task? Try to do that on its own. Then, try the fourth, then the fifth. Then put it all together.

I hope this helps!

5 Likes