How can I print an action five times in Python?

0
0
Asked By CuriousCoder94 On

I'm trying to figure out how to modify my code so that it prints a specific action five times in a row. Here's what I currently have:

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

How can I change it to repeat the action five times?

4 Answers

Answered By PythonPal77 On

You could also use string multiplication in Python to repeat the action:

```python
print(f'And the {people} gonna {action * 5}')
```
But remember, this will concatenate without spaces unless you format it to include spaces.

Answered By TechWhiz1985 On

You can use a for loop to print the action multiple times. Just do something like this:

```python
for i in range(5):
print(action)
```

Answered By CodeNinja44 On

Definitely need to clarify your question a bit more. Maybe share an example of what you're expecting the output to look like, like:

```
Bob runs.
Mike jumps.
And so on.
```
This could help others understand your requirements better!

Answered By ScriptSavant22 On

If you're looking to format it nicely in your string, you could do:

```python
print(f'And the {people} gonna {' '.join([action] * 5)})
```
This will put spaces 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.