Python Forum

Full Version: Python for Everybody 5.2 assignment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
if smallest is None:
smallest = num
elif num < smallest:
smallest = num

if largest is None:
largest=num
elif num > largest:
largest = num

then it works.
(Oct-07-2017, 04:56 PM)Lux Wrote: [ -> ]Well, the line print(num) seems to be why it's printing all the numbers- not sure if it's supposed to do that.
(Apr-16-2020, 12:05 PM)caseyfloyd6 Wrote: [ -> ]Removed spam content
Is this supposed to help with the question? Huh It is interesting, but how about you post it as a thread in the News and Discussions bar? Smile
(Apr-07-2020, 05:37 AM)vis1999 Wrote: [ -> ]please, solve my problem, when i put the term in output block(7,2,bob,10,2)again it ask enter a num and not show the result
Bro plss help me for 3.3 assignment
(Oct-07-2017, 03:58 PM)baba04201 Wrote: [ -> ]Hey guys- I'm on my last assignment for Python and I need some expert assistance please.

This is the assignment:
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.

This is my code:

largest = None
smallest = None
while True:
    try:
        num = raw_input("Enter a number: ")
        if num == "done":
            break
        print (num)
        num = int(num)
        if largest is None or largest < num:
            largest = num
        elif smallest is None or smallest > num:
             smallest = num
    except ValueError:
        print("Please, enter only numbers.")

print ("Maximum", largest)
print ("Minimum", smallest)
This is the Desired output:
Invalid input
Maximum is 10
Minimum is 2


This is my output:
7 ← Mismatch
2
bob
Please, enter only numbers.
10
4
Maximum 10
Minimum 2


I need help please. Wall

# check out this code

largest = None
smallest = None
while True:
inp = raw_input("Enter a number: ")
if inp == "done" : break
try:
num = int(inp)
except:
print ("Invalid input")
if smallest is None:
smallest = num
elif num < smallest:
smallest = num
elif num > largest:
largest = num

continue

print ("Maximum is", largest)
print ("Minimum is", smallest)
Quote:check out this code

largest = None
smallest = None
while True:
inp = raw_input("Enter a number: ")
if inp == "done" : break
try:
num = int(inp)
except:
print ("Invalid input")
if smallest is None:
smallest = num
elif num < smallest:
smallest = num
elif num > largest:
largest = num

continue

print ("Maximum is", largest)
print ("Minimum is", smallest)
First of all, this is the HOMEWORK SECTION, you aren't SUPPOSED TO WRITE CODE FOR OTHERS.
And, second, even if you write code, please use proper code tags
(Oct-07-2017, 03:58 PM)baba04201 Wrote: [ -> ]Hey guys- I'm on my last assignment for Python and I need some expert assistance please.

This is the assignment:
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.

This is my code:

largest = None
smallest = None
while True:
    try:
        num = raw_input("Enter a number: ")
        if num == "done":
            break
        print (num)
        num = int(num)
        if largest is None or largest < num:
            largest = num
        elif smallest is None or smallest > num:
             smallest = num
    except ValueError:
        print("Please, enter only numbers.")

print ("Maximum", largest)
print ("Minimum", smallest)
This is the Desired output:
Invalid input
Maximum is 10
Minimum is 2


This is my output:
7 ← Mismatch
2
bob
Please, enter only numbers.
10
4
Maximum 10
Minimum 2


I need help please. Wall





TRY THIS CODE:
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done":
break
num = int(num)
if largest is None or largest < num:
largest = num
elif smallest is None or smallest > num:
smallest = num
except ValueError:
print("Invalid input")
continue

print ("Maximum is", largest)
print ("Minimum is", smallest)
(Apr-07-2020, 05:37 AM)vis1999 Wrote: [ -> ]please, solve my problem, when i put the term in output block(7,2,bob,10,2)again it ask enter a num and not show the result
To ask another question, start a new thread , DON'T POST IN ANOTHER THREAD WRITTEN BY ANOTHER USER
(Apr-07-2020, 07:10 AM)gracePython3 Wrote: [ -> ]if smallest is None:
smallest = num
elif num < smallest:
smallest = num

if largest is None:
largest=num
elif num > largest:
largest = num

then it works.
Please don't post you solution, this is the homework section. And also, if you post codes in future, please use proper code tags
(Apr-18-2020, 04:40 AM)Saikumar Wrote: [ -> ]
(Apr-07-2020, 05:37 AM)vis1999 Wrote: [ -> ]please, solve my problem, when i put the term in output block(7,2,bob,10,2)again it ask enter a num and not show the result
Bro plss help me for 3.3 assignment
You need help in an assignment, post another thread, specifying all needs and requirements

(Apr-25-2020, 04:04 PM)Helious10 Wrote: [ -> ]
(Oct-07-2017, 03:58 PM)baba04201 Wrote: [ -> ]Hey guys- I'm on my last assignment for Python and I need some expert assistance please.

This is the assignment:
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.

This is my code:

largest = None
smallest = None
while True:
    try:
        num = raw_input("Enter a number: ")
        if num == "done":
            break
        print (num)
        num = int(num)
        if largest is None or largest < num:
            largest = num
        elif smallest is None or smallest > num:
             smallest = num
    except ValueError:
        print("Please, enter only numbers.")

print ("Maximum", largest)
print ("Minimum", smallest)
This is the Desired output:
Invalid input
Maximum is 10
Minimum is 2


This is my output:
7 ← Mismatch
2
bob
Please, enter only numbers.
10
4
Maximum 10
Minimum 2


I need help please. Wall





TRY THIS CODE:
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done":
break
num = int(num)
if largest is None or largest < num:
largest = num
elif smallest is None or smallest > num:
smallest = num
except ValueError:
print("Invalid input")
continue

print ("Maximum is", largest)
print ("Minimum is", smallest)
Please don't post you solution, this is the homework section. And also, if you post codes in future, please use proper code tags
(May-30-2020, 09:29 PM)sanjaykumar11 Wrote: [ -> ]I have upload python assignment 5.2 full solution in the video

https://www.youtube.com/watch?v=8bfPhZAJyto
https://www.youtube.com/watch?v=8bfPhZAJyto
Please, start another thread for this. It would also be preferred if you didn't show this, as students need to solve assignments on their own
hello cheakout man

Tongue
numList = []
while True:
        try:
            num = input("Enter a number: ")
            if num == 'done':
              break
            n = int(num)
            if n != 'done':
                Value = n
                numList.append(Value)
                smallest = min(numList)
                largest = max(numList)
        except:
            print("Invalid input")
            continue

print("Maximum is", largest)
print("Minimum is", smallest)
[Image: 85965237-947d3080-b9ab-11ea-875e-cf6ad8b3b227.png]
(Jun-29-2020, 02:02 AM)rafaelmoreno1 Wrote: [ -> ]hello cheakout man

Tongue
numList = []
while True:
        try:
            num = input("Enter a number: ")
            if num == 'done':
              break
            n = int(num)
            if n != 'done':
                Value = n
                numList.append(Value)
                smallest = min(numList)
                largest = max(numList)
        except:
            print("Invalid input")
            continue

print("Maximum is", largest)
print("Minimum is", smallest)
[Image: 85965237-947d3080-b9ab-11ea-875e-cf6ad8b3b227.png]

That's very good, but please don't post unnecessary stuff on a thread when a person is asking a question. If you want to show this, post it probably in the board/bar section.
Pages: 1 2 3