Brett.Morrison
Brett.Morrison

Reputation: 1

Repeating a function in Python a variable amount of times

For this code to work it has to repeat a variable amount (n) of times. It could change any time the program is run. I am extremely new to python and fairly new to programming in general, so I really don't know where to start.

def valueThree():
    name = input("What is the name?")
    valueOne = int(input("What is valueOne?"))
    valueTwo = int(input("What is valueTwo?"))
    valueThree = valueOne/valueTwo
    name_value = name, valueThree
    print(name_value)
n = int(input("How many times should valueThree() show up?"))

The program is supposed to execute valueThree n amount of times.

Upvotes: 0

Views: 1950

Answers (2)

ganduG
ganduG

Reputation: 615

You want a for loop.

for _ in xrange(n):
    valueThree()

Upvotes: 2

Erik Godard
Erik Godard

Reputation: 6030

You can write

for x in xrange(n):
    valueThree()

Upvotes: 1

Related Questions