-5

i'm new to programming and this has got me stumbling and i was thinking of doing something like this but i can't got further

num1 = int(input('What is the first number?:'))
num2 = int(input('What is the second number?:'))
num3 = int(input('What is the third number?:'))

[[After this my mind is thinking of elif statements and using [and,or]]

3 Answers3

1

Add all of your variables to a list and then you can use the max function like so max(lista)

num1 = int(input('What is the first number?: '))
num2 = int(input('What is the second number?: '))
num3 = int(input('What is the third number?: '))

lista = [num1, num2, num3]

biggest = max(lista)

print(f"{biggest} is the largest value.")
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 max.py
What is the first number?: 10
What is the second number?: 3
What is the third number?: 8
10 is the largest value.

Just for a little bonus, didn't include handling TypeErrors but want to give you some ideas where you can go with this little project:

while True:

    numbers = int(input("How many numbers would you like to enter: "))

    values = []

    for i in range(numbers):
        if i == numbers - 1:
            values.append(int(input(f"Enter 1 number: ")))
        else:
            values.append(int(input(f"Enter {numbers - i} numbers: ")))

    print(f"\nThe largest number entered was {max(values)}")
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 max.py
How many numbers would you like to enter: 5
Enter 5 numbers: 10
Enter 4 numbers: 8
Enter 3 numbers: 29
Enter 2 numbers: 13
Enter 1 number: 22

The largest number entered was 29
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20
0

Python's max(list) does the job for you.

If you wish to create a function that accepts arbitrary amount of inputs, you can create a function like this.

def my_function(*args):
    return max(args)
BerryMan
  • 145
  • 1
  • 15
0
num1=int(input('What is the first number?:'))
num2=int(input('What is the second number?:'))
num3=int(input('What is the third number?:'))
if(num1>num2 and num1>num2):
    print(num2, 'is the largest value')
elif(num2>num1 and num2>num3):
    print(num2, 'is the largest value')
else:
    print(num3, 'isenter code here the largest value')
  • Please add more details, possibly an explanation of your answer so its easy for others to understand. Appreciate it! – Srijith Sep 17 '18 at 06:13
  • Thanks for good advice, i will try to explain it. It was very simple program i made it as it is simple that's why i didn't explain it. – Krishna Bihari Sep 18 '18 at 05:49