Advice with if statements and python math comparators and input function -


the program should ask whole number before printing anything. program must check input numbers between 0 , 5. fail if number of digits entered other 5. failed input can terminate program appropriate error message. inputted numbers may duplicates. (ex. 3, 3, 3, 0, 0 acceptable input.) need getting program print out '.' if input=0. , asking 5 digits @ same time.

nums[] nums= input number=int(input) n in number:    if n<0 , n>=5 , if len(n)=5:       print 'x'*n       elif n==0 , if len(n)==5:       print '.'    elif n>0 or n<5 or len(n)!=5:       print "invalid input" 

your program bit messed up.. forgive me if i'm being little rough

first, isn't allowed:

nums[] 

second,

number = int(input)  

is invalid, because input not valid number.

third,

for n in number 

number integer, not list!

fourth, if number list:

len(n) ==5: 

will still invalid, because n integer!

try this:

input_list = raw_input("enter number list: ") try:     number=eval(input_list) except:     number = list(input_list) if len(number) == 5:     n in number:        if n<0 , n>=5:           print 'x'*n           elif n==0:           print '.'        #elif n>0 or n<5: #not needed, make input invalid         #  print "invalid input" else:   print "invalid input" 

execution:

>>>enter number list: [3,3,3,0,0]    xxx    xxx    xxx    .    . 

or:

>>>enter number list: 33300    xxx    xxx    xxx    .    . 

i assume python version 2.x

is want?


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -