Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in my code
#1
Hello everyone,
I am working on my school homework that is quite easy for some professional, but I have troubles with few things that I tried to change but obviously I can't make them work.
p=[]
def number():
    c=1
    try:   
        x=int(input("Insert integer number:"))
        p.append(x)
        for z in p:
            nn=p.sort(p) #nn=new number
        print(p,"->",nn)
        
    except ZeroDivisionError: 
        print("You cant divide by Zero")
        c=0
    except ValueError:
        print("You didn't insert integer number")
        c=0
    return c

while c!=0:
    number()
The point of this exercise is to insert numbers until we insert 0, than every inserted number - every digit of this number sort in order from the biggest to smallest.

After making this, the program tells me
Output:
1# name "c" is not defined - when I define c as 1 (c=1), next problem income 2# File "/Users/adam/Desktop/python/kod2.py", line 12, in cisla nc=p.sort(z) TypeError: sort() takes no positional arguments
- after 2nd problem I tried to delete "p" from parentheses and than my program did this:
Output:
Insert integer number: --I inserted 23--- program did this: [23] --> None
Does anyone have any solution how to solve this? I tried almost everything...
Reply


Messages In This Thread
Error in my code - by TumbleR - Nov-26-2019, 10:19 PM
RE: Error in my code - by stullis - Nov-26-2019, 10:40 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020