Python Forum
program is related to leading zeros
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
program is related to leading zeros
#4
You are getting the reminder on line 15 and print it. Not the tens

#request input from the user
num=eval(input("please enter an integer in the range 0....9999"))
if num<0:
    num=0
if num>9999:
    num=9999
print(end="[")
#extract and print thousand place digit
digit=num//1000
print(digit,end=" ")
num%=1000
#extract and print hundred place digit
digit=num//100
print(digit,end=" ")
digit = num // 10 # added
print(digit, end=' ') #added
num%=10
#remainder is the one place digit
print(num,end=" ")
print("]")
You should never use eval() to get a number as an input. It's very dangerous if one's input is a valid Python code. It will be executed
num = int(input("Enter a number between 1 and 9999: "))
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
program is related to leading zeros - by amrita - Apr-13-2017, 05:54 AM
RE: program is related to leading zeros - by buran - Apr-13-2017, 06:41 AM
RE: program is related to leading zeros - by wavic - Apr-13-2017, 06:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Removing leading whitespaces palladium 1 745 Mar-24-2023, 04:15 PM
Last Post: bowlofred
  Removing leading\trailing spaces azizrasul 8 2,808 Oct-23-2022, 11:06 PM
Last Post: azizrasul
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,803 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  -i option changes sys.path (removes leading empty string '') markanth 6 2,043 Aug-26-2022, 09:27 PM
Last Post: markanth
  remove zeros at the end of a number Frankduc 7 2,212 Feb-25-2022, 03:48 PM
Last Post: Frankduc
  Solving for zeros of an equation! fmitchell17 0 1,862 Apr-05-2021, 07:49 PM
Last Post: fmitchell17
  Although this is a talib related Q it's mostly related to python module installing.. Evalias123 4 5,775 Jan-10-2021, 11:39 PM
Last Post: Evalias123
  Dataframe Removes Zeros JoeDainton123 2 4,445 Sep-17-2020, 12:47 PM
Last Post: scidam
  How to keep leading zeros with pandas? eeps24 1 6,632 May-20-2020, 07:51 PM
Last Post: deanhystad
  Cancelling 'open directory' leading to crash Fairbz_ 1 2,212 May-08-2020, 03:14 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

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