- 1

Pls help me. How can I write a python program to find the largest number among three input number

I don't kmow how to do this

6th Jul 2021, 10:07 AM
Ogunjimi Segun Toba
Ogunjimi Segun Toba - avatar
4 Respostas
+ 3
Yaroslav Vernigora , i think a basic for loop is not as short as the other solutions but is a good coding exercise: # create and initialize a list of 3 numbers or any other count of numbers # create and initialize a variable like <max_num> that should hold the largest number. initialize with the first number from list # use a for loop to iterate through the list # compare the current element in loop against the value in <max_num> # if current element in loop is larger than the value in <max_num> assign current element to <max_num> # finally (when loop is terminated) print the content of <max_num> happy coding and good success!
6th Jul 2021, 11:22 AM
Lothar
Lothar - avatar
+ 2
Hi! 1. enter three values in three different variables. 2. create a fourth variable, which will be the maximum. 3. assign the maximum variable to the value of the first variable 4. compare this maximum variable with the second value. if the second variable is greater than the maximum, then assign the value of the second variable to the maximum variable 5. compare the maximum variable with the third variable, if the third variable is greater, assign this value to the maximum variable. 6. display the value of the maximum variable on the screen
6th Jul 2021, 10:14 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
nums = 4, 42, 2 print(max(nums))
6th Jul 2021, 10:09 AM
visph
visph - avatar
+ 1
# or: print(max(4, 42, 2))
6th Jul 2021, 10:11 AM
visph
visph - avatar