Okay I don't get this problem at all:

``````import random

def chance(number):
number = input
for each in xrange(number):
n = random.randrange(100)+1
return n

def extreme(x):
z = x + 5
y = z - 3
return z, y

#main
repeat = 0
while repeat != 2:
x = input("Enter a value for x: ")

z, y = extreme(x)
print x," + 5 = ",z
print z," - 2 = ",y

n = chance(number)
input = raw_input("How many random numbers do you want?: ")
print n

repeat=input("Do you want to go again? Yes [1] or no [1]: ")

raw_input("Press Enter to exit!")``````

This is copied from the homework website my teacher made (as this is an online Python Course):

Make a course dev worth at least 20 marks which includes:

a function with two positional parameters that returns two values (both integers or real numbers)

a function which generates random numbers and returns them (any amonnt you want)

a function with one parameter, which it gets from a random number generator, that returns two values (strings are returned)
asks if you want to do it again (y or n)

I have no idea how to do the third option, and I had it working before but I must've changed something and I don't know what.

I need help with my homework :( but no one's replying. [note: this comment was just to move this thread back to the top of the list]

Q: a function with two positional parameters that returns two values (both integers or real numbers)
A: hint, your function receives two values, let's say x, y and does some calculations on each and returns the changed values

Q: a function which generates random numbers and returns them (any amount you want)
A: hint, since you may want more than one random number, best to return a list of random numbers

Q: a function with one parameter, which it gets from a random number generator, that returns two values (strings are returned)
A: hint, take the first element from your returned r_list and pass it as the argument to a function that incorporates this number into two different strings then return the two strings

For instance if your random number is r, then create two silly strings:
s1 = "I won \$" + str(r) + " in the lottery!"
s2 = "I plan to retire at age " + str(r)

I need help with my homework :( but no one's replying. [note: this comment was just to move this thread back to the top of the list]

This isn't a place to come and have your homework done for you. Forum-goers here typically don't just give out solutions to homework, as that would be immoral and you'd never learn anything.

When it comes to homework or projects the best bet for getting help is to give us the code that you've tried and the errors or incorrect results that it has produced. We can then give you tips and help you tweak the code, but we do not provide e2e solutions. Not for homework, anyway... I suggest reading this announcement

Oh and we know what a *bump* is; no need to explain.

So how would I make it? The instructions are really confusing:S

What particular part of it are you having trouble with? You cant just post your entire assignment.

The third part is what I'm having trouble with (though I accidentally called it Third Option, and I did say which one]. I don't understand how I can return two variables.

You can return it like this:

``````def returnTwoThings():
return 1,2

a,b = returnTwoThings()
print a
print b
#output
#1
#2``````

Ah, I see... but then I don't understand why my previous program isn't working. Is something wrong with it?

``````import random

def chance(number):
number = input
for each in xrange(number):
n = random.randrange(100)+1
return n

def extreme(x):
z = x + 5
y = z - 3
return z, y

#main
repeat = 0
while repeat != 2:
x = input("Enter a value for x: ")

z, y = extreme(x)
print x," + 5 = ",z
print z," - 2 = ",y

n = chance(number)
input = raw_input("How many random numbers do you want?: ")
print n

repeat=input("Do you want to go again? Yes [1] or no [1]: ")

raw_input("Press Enter to exit!")``````

What about the number variable, i cant find where it is made:

``````import random

def chance(number):
number = input
for each in xrange(number):
n = random.randrange(100)+1
return n

def extreme(x):
z = x + 5
y = z - 3
return z, y

#main
repeat = 0
while repeat != 2:
x = input("Enter a value for x: ")

z, y = extreme(x)
print x," + 5 = ",z
print z," - 2 = ",y

n = chance(number)   #<--------- Where is number made
input = raw_input("How many random numbers do you want?: ")
#also never use the word input as a word, otherwise when you call input() again it will not work. Use a different variable name
print n

repeat=input("Do you want to go again? Yes [1] or no [1]: ")

raw_input("Press Enter to exit!")``````

I'm stuck. I've tried everything.

``````import random

n = 0

def chance():
global n
number = raw_input("How many random numbers do you want?: ")
for each in str(number):
n = random.randrange(100)+1
return n

def extreme(x):
z = x + 5
y = z - 3
return z, y

#main
repeat = 0
while repeat != 2:
def chance():
global n
number = raw_input("How many random numbers do you want?: ")
for each in str(number):
n = random.randrange(100)+1
return n

def extreme(x):
z = x + 5
y = z - 3
return z, y

x = input("Enter a value for x: ")
z, y = extreme(x)
print x,"+ 5 =",z
print z,"- 2 =",y

chance()
print n

repeat=input("Do you want to go again? Yes [1] or no [1]: ")

raw_input("Press Enter to exit!")``````

Can someone help me fix it up so that it prints as many different random numbers as asked for? I can't quite get it.

Okay so here is some working code. Make sure you can understand everything in it, if you dont ask questions make sure you can understand why things are the way there are:

``````import random

def chance():

number = raw_input("How many random numbers do you want?: ")
l = []
for each in range(int(number)):
n = random.randrange(100)+1
l.append(n)
return l

def extreme(x):
z = x + 5
y = z - 3
return z, y

#main
repeat = 0
while repeat != 2:

x = input("Enter a value for x: ")
z, y = extreme(x)
print x,"+ 5 =",z
print z,"- 2 =",y

for f in chance():
print f

repeat=input("Do you want to go again? Yes [1] or no [2]: ")

raw_input("Press Enter to exit!")``````

What's an append?

What's an append?

Append is a way to "add on" to the "end" of the list... Here's a visual example:

``````>>> my_list = [1,2,3]
>>> my_list
[1, 2, 3]
>>> my_list.append(4)
>>> my_list
[1, 2, 3, 4]
>>> my_list.append([9,8,7])
>>> my_list
[1, 2, 3, 4, [9, 8, 7]]
>>> my_list.append(-1)
>>> my_list
[1, 2, 3, 4, [9, 8, 7], -1]
>>>``````

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.