answersLogoWhite

0

In python, type the following into a document.

NOTE: Sentences following a # symbol are comments, and are not necessary for the program to run.

#!/usr/bin/python

#This program takes a input from a user and reverses it.

number = input("Type a number: ") #This takes input from a user.

a = len(number) #This finds the length of the number

reverse = "" #This sets the variable reverse to an empty string.

for i in number:

a = a-1 #The places in a string start from 0. The last value will be the length minus 1.reverse = reverse + number[a] #Makes the number's last digit the new string's first.

print("The reverse of", number, "is", reverse + ".") #prints the resulting string.

This program will take any sequence of characters and reverse them. The final value is a string, but if an integer is needed, one needs only to add the line

reverse = int(reverse)

above the print statement.

However, this will stop the program from being able to reverse strings, as it is not possible to convert a string to an integer if it is not a number.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What does the print command do in Python?

The print command is a way to display output to the console. The hello world program, for example, can be written in python as simply print("Hello world") Other values can also be used in a print statement: a = 4 print(a) #will print the number 4


Program for check a number is even or odd using PYTHON language?

This program checks whether a number is odd or even. NOTE: This site removes formatting from answers. Replace (tab) with a tab or four spaces. #!/usr/bin/python print("Type a number.") n = input(": ") l = len(n)-1 even = ("02468") if n[l] in even: (tab)print(n, "is even.") if n[l] not in even: (tab)print(n, "is odd.")


How you write a program in c plus plus to print plaindromic numbers from 1 to n?

To check if a number is a palindrome, reverse the number and see if it is equal to the original number. If so, the number is a palindrome, otherwise it is not. To reverse a number, use the following function: int reverse(int num, int base=10) { int reverse=0; while( num ) { reverse*=base; reverse+=num%base; num/=base; } return(reverse); }


How do you Write a program in 'c' language which accepts int numbers from the users print its reverse number x function which return value?

question clarity


What is the purpose of print strings in python?

It means that python will print(or write out) a value you input.


What is used in python programming for space in output?

I interpreted your question as this: What is used in Python for adding a blank line to the output? If you are looking for this, a simple print statement will do: print #in python 2.x or print() #in python 3.x If that wasn't what you were looking for, change the question to be more clear.


Which of the following function convert an object to a string in python?

By using "str()". Example: number = 2 yourNumber = print("Your number is %s!") % (str(number))


What is the meaning of print python programming?

In Python; the "print" feature will simply output something (defined by you) onto the screen. For example: print("Hello") would output "Hello" to the screen!


Program for generate multiples of 9 upto 500 using PYTHON?

In order to display multiples of 9 up to 500 I would use a while loop with the condition number < 500. For example: #set number to the first multiple of 9 number = 9; while number < 500: print number; #add 9 to the number number += 9; Note: I put semicolons at the end of each line out of habit. Python does not require this. Note: lines beginning with # are comments The above code will print the current value of number, then add 9 to it. It will continue to do this until number is greater than or equal to 500.


How do you print hello world in python?

by opening his mouth!


C plus plus program to print number patterns?

bghjg


What a program that accepts two numbers and tell whether the product of the two number is equal to or greater than 1000?

You can create a simple program in Python to achieve this. The program will prompt the user to input two numbers, calculate their product, and then check if the product is equal to or greater than 1000. If it is, the program will print a message confirming that; otherwise, it will indicate that the product is less than 1000. Here's a quick example: num1 = float(input("Enter the first number: ")) num2 = float(input("Enter the second number: ")) if num1 * num2 >= 1000: print("The product is equal to or greater than 1000.") else: print("The product is less than 1000.")