How to print string multiple times on new line - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to print string multiple times on new line (/thread-30019.html) |
How to print string multiple times on new line - ace19887 - Sep-30-2020 How do I get the below to print the output 4 x and each print to start on a new line name = input("What is your name: ") age = input("What is your age: ") result = str(2020 + (100 - int(age))) print(4 * ("Hello " + name +" you will be 100yrs old in the year " + result + ". "))Thanks RE: How to print string multiple times on new line - ndc85430 - Sep-30-2020 Call print 4 times?
RE: How to print string multiple times on new line - Naheed - Sep-30-2020 print(*4*(("Hello " + name +" you will be 100yrs old in the year " + result + ". "), sep='("Hello " + name +" you will be 100yrs old in the year " + result + ". "') RE: How to print string multiple times on new line - buran - Sep-30-2020 (Sep-30-2020, 12:54 PM)Naheed Wrote: print(*4*(("Hello " + name +" you will be 100yrs old in the year " + result + ". "), sep='("Hello " + name +" you will be 100yrs old in the year " + result + ". "') Seriously? For start - it will raise SyntaxError... RE: How to print string multiple times on new line - Naheed - Sep-30-2020 (Sep-30-2020, 01:00 PM)buran Wrote: Seriously? For start - it will raise SyntaxError...Please, put forward your suggestions so I can find the key areas for improvement. RE: How to print string multiple times on new line - buran - Sep-30-2020 (Sep-30-2020, 01:13 PM)Naheed Wrote: put forward your suggestions so I can find the key areas for improvementfirst of all - try to fix the SyntaxError in your code then read on loops RE: How to print string multiple times on new line - perfringo - Sep-30-2020 In spoken language: "print string four times separated with newline" Translation into Python: name = 'Guido' age = '64' message = f'Hello {name}! You will be 100 years old in {2020 + (100 - int(age))}' print('\n'.join(message for i in range(4))) RE: How to print string multiple times on new line - buran - Sep-30-2020 for _ in range(4): print(f"Hello {name}. You will be 100yrs old in the year {result}.") |