1. Use a recursive function to print the five characters you have entered in reverse order
#-*-Coding:utf8-*-
# AUTHOR:WXQ
#python 2.7
#题目: The 5 characters entered are printed in reverse order using the recursive function invocation method.
#定义一个字符串, waiting for user input
string = input ("Please enter a string:")
#定义一个变量
def f (x):
if x = =-1: #当变量的长度是-1, return
Return '
else: #否则返回字符串的位置向后移1位 until the length of the variable is-1
return string[x] + f (x-1)
Print (f (Len (String)-1))
3. Determine if a number is prime
# User Input number
num = Int (input ("Please enter a number:"))
# prime number greater than 1
If num > 1:
# View Factors
For I in Range (2,num):
if (num% i) = = 0:
Print (num, "not prime number")
Print (I, "multiply in", num//i, "yes", num)
Break
Else
Print (num, "is prime")
# If the number entered is less than or equal to 1, not prime
Else
Print (num, "not prime number")
4. Define the factorial function, pass an int parameter, return all its digits multiplied by the number of ringgit, such as 1234 return (1*2*3*4)
1234//10//10//10
def factorial (i):
result = 1
while (I/10 > 0):
Result *= I% 10
i = Int (I/10)
# result *= I
return result
Print (factorial (1234))
#########
Indentationerror:unindent does not match any outer indentation level appears in Python
47089473
Python newspaper "indentationerror:unexpected indent" solution.
10379157
Python Exercise 2