0

I would like to know if there is some sort of command or function that I can import that would allow me to run a command multiple times based on the value of an input. That might not make any sense but hopefully it will from this ↓

num_of_rounds = input(int("type the amount of rounds you want to play"))
for num_of_rounds:
  print("test")

This isn't working for me and I don't know how to make it work.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • also could the same thing work but instead of it being input command could it be a function: ````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````def rounds_func(number): for number: print("test") ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` – Collin Dehmer May 27 '21 at 22:23
  • 2
    You mean `int(input(...))`, not `input(int(...))` – khelwood May 27 '21 at 22:24

2 Answers2

2

Use a range with a dummy variable _.

num_of_rounds = int(input("type the amount of rounds you want to play"))
for _ in range(num_of_rounds):
    print("test")
wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • 3
    @Jared The [de facto standard](https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python/5893946) in Python is to use `_` as the name for any unused variables. – Woodford May 27 '21 at 22:34
  • The official python documentation actually shows `x` being used for for loops https://wiki.python.org/moin/ForLoop so no your wrong `_` is not the standard, I would trust the python.org docs a lot more then a random SO question. –  May 27 '21 at 22:37
  • @Jared That's the wiki, not the official docs. But here's a slightly more authoritative source than "a random SO question": [Pylint docs - Variables checker Options](http://pylint.pycqa.org/en/latest/technical_reference/features.html#variables-checker-options) - *"**dummy-variables-rgx**: A regular expression matching the name of dummy variables (i.e. expected to not be used). Default: `_+$`..."* – wjandrea May 27 '21 at 22:50
  • @wjandrea the domain name of the website is `wiki.python.org` python.org is the official python website, the link you have given me `pycqa.org` is some random website, not the official source. Provide actual proof from a creditable source, else im not gonna take you seriously. –  May 27 '21 at 22:53
  • @Jared I just looked at the initial link you sent, and actually, all of those loops use `x`... It's not being used as a dummy variable. Either way, IDK why you don't believe me. The wiki is user-editable, it says so right on the homepage. And Pylint is a tool used by thousands of devs. – wjandrea May 27 '21 at 23:12
0

Maybe something like this would work:

def rounds():
    num_of_rounds = int(input("type the amount of rounds you want to play"))
    for i in range(num_of_rounds):
        print("test")
rounds()
Patrick Gorman
  • 132
  • 1
  • 8