Question

In: Computer Science

Write a python code to Design and implement a function with no input parameter which reads...

Write a python code to Design and implement a function with no input parameter which reads a number from input (like 123). Only non-decimal numbers are valid (floating points are not valid). The number entered by the user should not be divisible by 10 and if the user enters a number that is divisible by 10 (like 560), it is considered invalid and the application should keep asking until the user enters a valid input. Once the user enters a valid input, the program calculates the reverse of the input number (for 153, the reverse is 351) and prints the result and returns the results.Do not use try and except. Use Main function.

Solutions

Expert Solution

Python code:

#defining function which returns the reverse of number
def reverse():
    #asking for number
    num=input("Enter a number: ")
    #infinite loop till valid number is entered
    while True:
        #checking if the number is floating point
        if("." in num):
            #asking for valid number
            num=input("Enter a valid number: ")
        else:
            #converting number to integer
            num=int(num)
            #checking if number is divisible by 10
            if(num%10==0):
                #asking for valid number
                num=input("Enter a valid number: ")
            else:
                #printing reversed number
                print("Reversed number is "+str(num)[::-1])
                #returning reversed number
                return str(num)[::-1]
def main():
    #printing Returned value
    print("Returned value is "+reverse())
if __name__ == "__main__":
    main()


Screenshot:


Input and Output:


Related Solutions

Design and implement a function which has one input parameter which is a number which is...
Design and implement a function which has one input parameter which is a number which is greater than 50, called num. Then the function will create a dictionary whose keys are 2 and 3 and 4 and 5 and 6 and 7 and 8 and 9. Then the function calculates the values for each of the above keys. The value for a key is all the numbers between 2 and input “num” that are divisible by the key. The function...
Implement in Python a script that does the following: 1) reads input from a supposed file...
Implement in Python a script that does the following: 1) reads input from a supposed file called firstnames_2.txt. 2) processes the input and writes and saves the output to a file. NOTE: Please make sure that the names are written in the outfile with one name on each line no comma ( , ) after the name in the output
Write A function with an input parameter which is a string arithmetic statement which contains only...
Write A function with an input parameter which is a string arithmetic statement which contains only alphabet variables and binary operations including +, -, *, / and % and checks whether the statement is a valid arithmetic statement or not. If the statement is valid, the function returns true, otherwise returns false. • The statement might contain parenthesis as well. For instance: • a+b*a+c/c%y • (a+b)*(a/d-(a/b)) • You can make this assumption that the variable names contain only one alphabet...
- Write a function with no input parameter which keeps asking the user to enter positive...
- Write a function with no input parameter which keeps asking the user to enter positive numbers until the user enters an invalid input. (An invalid input is an input which includes at least one alphabet, like 123d4). The program should print the Max and Min of the numbers the user had entered as well as the distance between the Max and Min. (Remember to calculate the absolute distance). The function does not return anything
- Design and implement a function with no input parameters. The function keeps receiving a number...
- Design and implement a function with no input parameters. The function keeps receiving a number from input (user) and adds the numbers together. The application keeps doing it until the user enter 0. Then the application will stop and print the total sum and average of the numbers the user had entered.
Write a parameterized function that takes in a file name as a parameter, reads the file,...
Write a parameterized function that takes in a file name as a parameter, reads the file, calculates the factorial of each number, and displays a formatted output as follows: Factorial of 10 = 3628800 Factorial of 5 = 120
Using Python Question 1 Write an input function. Then use it to supply the input to...
Using Python Question 1 Write an input function. Then use it to supply the input to following additional functions: i) Print multiplication table of the number from 1 to 12. ii) Print the sum of all the numbers from 1 to up the number given. iii) Print if the number supplied is odd or even. Question 2 Write function that asks for input from a user. If the user types 'end', the program exits, otherwise it just keeps going.
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
in c++ Write a function that takes a C string as an input parameter and reverses...
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Design and write a python program that reads a file of text and stores each unique...
Design and write a python program that reads a file of text and stores each unique word in some node of binary search tree while maintaining a count of the number appearance of that word. The word is stored only one time; if it appears more than once, the count is increased. The program then prints out 1) the number of distinct words stored un the tree, Function name: nword 2) the longest word in the input, function name: longest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT