Base type (b)

# 1, the user enters a value, use a comparison operator to confirm the user input is an even number? 
# Is an even output True, False not output
True the while: 
the try:
NUM = INPUT ( 'Enter an integer:')
IF int (NUM)% 2 == 0:
Print (True)
BREAK
the else:
Print (False)
BREAK
the except:
'! Please enter an integer' print ( )

 

 

 

# 2, selling oranges Calculator: write a piece of code, the user is prompted orange prices, then buy a randomly generated number (between 5-10 pounds) pounds, finally calculate the amount to be paid!
import random

True the while:
the try:
. price = a float (INPUT ( 'Enter the price of orange:'))
weight = the random.randint (5,10) + random.random ()
Money = weight. price *
Print ( 'orange price { }, purchased {: .2f} pounds, a total of {: .2f} meta! 'the format (. price, weight, Money)).
BREAK
the except:
Print ('! Please enter the number ')

 

 

 

# 3, using the random string concatenation module and method 130 begins with a randomly generated phone number. 
Random Import
Phone = the random.randint (13000000000,13099999999)
Print (Phone)

 

 

 

# 4, the existing string = str1 "! IS the PHP Programming Language The Best in The World" 
# a requirement: PHP given string is replaced with the Python
# two requirements: After replacement, the string of spaces split point split by a listing

str1 = "the Best the PHP iS Programming Language in the World!"
str2 = str1.replace ( 'the PHP', 'the Python')
Print ( 'str1 =', str1)
Print ( 'str1 memory address : ', ID (str1))
Print (' = str2 ', str2)
Print (' str2 memory address is: ', ID (str2))
List1 = str2.split (' ')
Print (List1)

 

Note: This method string replace method, there is a return value, instead of being replaced in the original object basis. From a string (str2) after the replacement is completed and the original string (str1) memory address can be seen, not point to the same object.

 

 

# 5, write code that prompts the user to enter seven digits 1-7, representing the Monday to Sunday, the printout "Today is the week the X-" 
List1 = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday' , "Friday", "Saturday", "Sunday"]
the while True:
the try:
Today = int (iNPUT ( 'enter 1-7, any of a number:'))
Print (List1 [-Today. 1])
BREAK
the except:
Print ( "Please enter an integer between 1-7! ')

Guess you like

Origin www.cnblogs.com/Super-Treasure/p/12129082.html