How can I repeat an action five times in my code?

0
2
Asked By CodeNinja42 On

I'm trying to make my Python code print an action five times in a row. Here's what I have so far:

```python
people = input("People: ")
action = input("Action: ")
print(f'And the {people} gonna {action}')
```

What's the best way to modify this so that it repeats the action five times?

2 Answers

Answered By TechieTom On

You can use a for loop to do this! Just set it up like `for i in range(5): print(action)` and it'll loop five times to print the action.

Answered By PythonPro99 On

Instead of manually printing the action multiple times, you can also do this: `print(f'And the {people} gonna ' + f'{action} ' * 5)`. This will concatenate the action with spaces between each repeat.

CuriousCoder88 -

But how do I make sure there's a space between each action?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.