![]() |
class homework - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: class homework (/thread-30606.html) |
class homework - mohan10216 - Oct-28-2020 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. RE: class homework - Askic - Oct-28-2020 (Oct-28-2020, 12:40 AM)mohan10216 Wrote: Hi I wanted to get some help on how I could solve this python problem as I am just a beginner in python. Perhaps, I didn't understand what is the actual assignment, but this seems to be what you need: last_name = input("Enter your last name: ") school_ID = int(input("Enter your school number: ")) print(last_name[:5], school_ID)This code will print only 5 letters of the last name followed by ID number. RE: class homework - jefsummers - Oct-28-2020 Proposals don't handle if there are any spaces. @Askic response assumes you have covered slices of strings (that colon format), where I am thinking they are trying to teach you loops. Have you covered slices? Suggest: get your inputs like you are doing, but would not bother converting to an int Get the first 5 characters of the last name, using slice notation if that is allowed Remove a space if present (hint - look at the replace function and replace with '') concatenate the result with the school_id. |