-2

so I am still learning Python so this should be rather easy to answer for some of you experts...

1) How can you make it so only numbers are accepted as an input?

def check_only_digit():
    digits = input("Please input a number ")
    if digits in "0123456789":
        print("Working")
    else:
        print("Not working")

check_only_digit()

This will print "Working" if the inputted is a number in 0123456789 but only is this order. What I am asking is there any way to make it in any order?

2) How can I make the users digit round UP to the nearest 10?

def round_up():
    users_number = input("Please input a number you want rounded ")
    answer = round(int(users_number), -1)
    print (answer)

round_up()

3) Is there anyway to add a number onto the end of another number? For example for 1+1, instead of equaling 2, can it equal 11?

I would like to thank you all for your responses in advance.

JDog
  • 7
  • 1
    Question 1 is a duplicate of [How can I limit the user input to only integers in Python](http://stackoverflow.com/questions/23326099/how-can-i-limit-the-user-input-to-only-integers-in-python). – Aurora0001 Oct 16 '16 at 15:23
  • 1
    Question 2 is an exact duplicate of [Python - round up to the nearest ten](http://stackoverflow.com/questions/26454649/python-round-up-to-the-nearest-ten). – Aurora0001 Oct 16 '16 at 15:24
  • Question 3 is a duplicate of [Merge two integers in Python](http://stackoverflow.com/questions/12838549/merge-two-integers-in-python). – Aurora0001 Oct 16 '16 at 15:25
  • I'm not sure I understand them answers. I would much prefer it if someone could help me with my examples. – JDog Oct 16 '16 at 15:39
  • Also the second one I need to the nearest ten. Any idea how? – JDog Oct 16 '16 at 22:03

1 Answers1

0

For Answer 1:

    def check_Numbers():
         number=input("Enter a number: ")
         try:
              number=int(number)
              print("Working")
         except(ValueError):
              print("Not Working")

For Answer 2:

    def rounding_Off():
        userNumber=float(input("Enter a floating point number to round off: "))
        roundedOff=round(userNumber,-1)
        return roundedOff

For Answer 3:

    def addNumbers():
         number1=input("Enter one number: ")
         number2=input("Enter another one: ")

         newNumber=number1+number2
         return int(newNumber)
         #return newNumber <----- This if you want to get your number in string format.
Rishikesh Jha
  • 540
  • 3
  • 11