Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (immanuelv):

can anyone help me with python?

OpenStudy (anonymous):

I know a little python... what might i be able to help you with?

OpenStudy (immanuelv):

Write a function named smallestValue that accepts five integers and return the smallest integer accepted. Do not use a List or any Build-in functions

OpenStudy (immanuelv):

i have no idea to do it rather than calling in a built in function :(

OpenStudy (anonymous):

hmm, lemme check my book I mainly do game development with python rather than anything else. :P

OpenStudy (immanuelv):

thanks mate :)

OpenStudy (anonymous):

hmm... is this what your looking for: http://www.pythonlearn.com/html-008/cfbook005.html (check section 4.2)

OpenStudy (anonymous):

@immanuelv yo, you still there?

OpenStudy (immanuelv):

im here @rdvl97 :)

OpenStudy (anonymous):

cool :)

OpenStudy (anonymous):

did you check the link?

OpenStudy (immanuelv):

im checkin it right now

OpenStudy (immanuelv):

it shows the built in function .... but i cant use it :(

OpenStudy (anonymous):

Gah! sorry i forgot :(

OpenStudy (immanuelv):

yeah... my teacher finds ways to make my life complicated lol

OpenStudy (anonymous):

does it have to accept numbers with multiple digits?

OpenStudy (immanuelv):

i guess.... it would've been easy if i could use arrays ...but he wont give me credit for it ;(

OpenStudy (anonymous):

are you able to use if, else, elif statements? If you can, I think I have an idea.

OpenStudy (anonymous):

im pretty sure those arent considered built in functions...

OpenStudy (immanuelv):

yea i can use if elifs

OpenStudy (anonymous):

wait...

OpenStudy (anonymous):

are you able to use tuples?

OpenStudy (immanuelv):

haha well he didnt say anything about tuples... so i guess i can :)

OpenStudy (anonymous):

lol cool that makes things a bit simpler :)

OpenStudy (e.mccormick):

Well, if you had to hard code it you could do a tree of if-then, but it is probably better to just keep track of the first as a temp, check it against the next, if it is smaller replace the temp, if not, keep going, until at the end.

OpenStudy (anonymous):

For replacing the "min" function, set up a loop to go through each integer and compare it against static integers if 1 <= a elif 2 <= a elif 3 <= a elif 4 <= a elif 5 <= a etc.. its not efficient but it works

OpenStudy (e.mccormick):

@rdvl97 Well, if you can't use lists, there is no need to loop.

OpenStudy (anonymous):

cool

OpenStudy (immanuelv):

something like this would work? num = int(input("enter a number")) small = num for num in range (5) if num < s s = num num = int(input("enter a number")) print(num) ?

OpenStudy (anonymous):

@e.mccormick sorry, I don't know why I said loop. :P

OpenStudy (e.mccormick):

Not really. You only have 1 number there. They seem to be asking for all 5 at once to go to the function.

OpenStudy (e.mccormick):

If you look at the instructions, it takes in 5 ints at once and returns the lowest. It is not allowed to use a list, which is the python version of an array for most other languages, and no built in functions so it is limiting you to some pretty basic stuff. Mist as well take the ints as seperate variables and just walk through them, save the lowest to a temp variable. Then return the temp.

OpenStudy (immanuelv):

would this work? a = int(input("") b = int(input("") c = int(input("") d = int(input("") e = int(input("") if (a < b && a < c && a < d && a < e): return a elif (b < a && b < c && b < d && a < e): return b elif (c < a && c < b && c < d && c < e): return c elif (d < a && d < b && d < c && d < e): return d elif (e < a && e < b && e < c && e < d): return e something like that works?

OpenStudy (e.mccormick):

Umm.... yah.... but it is awkward. if a < b: t = a else: t = b if c < t: t = c and so on. Then return t.

OpenStudy (e.mccormick):

Your first one sets the temp t to the lower of a or b. Everything else just sees if it is lower than t and if so, sets t to that.

OpenStudy (immanuelv):

that makes sense... its easier than my method.... thanks mod @e.mccormick !!!

OpenStudy (e.mccormick):

It is sort of like a single pass of a simple sort.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!