The sample in Chapter 2 has been modified as follows.
--Points to check
--Distinguishing between double quotes "" "and single quotes"'" in strings
――Both can be used, but it is a prerequisite to use them as a pair.
: x: print (' this is a test ** ") or: x: print (" ** this is a test ')
: o: print (' this is a test ') or: o: print (** "** this is a test **" **)
--When double quotation mark "" "or single quotation mark"'" exists in the character string, it can be realized by the following two types of correspondence.
:o: print( " this is Tom's pen ")
:o: print( ' this is Tom's pen ')
:o: print( ' I said "Hello!" ')
:o: print( " I said "Hello!" ")
--The output result of the input function always returns with the character type.
--Order of operation code
In the United States, PEMDAS (Parentheses: parentheses, Exponents: power,
Use the acronym Multiplication: Multiplication, Division: Division, Addition: Addition, Subtraction: Subtraction).
--If you enter multiple character strings you want to output in the print function, a space will be inserted between them.
sample02.py
#Ask for the dog's name
dog_name = input('What is the name of the dog?')
#Ask the age of the dog
dog_age = input('How old is the dog?')
#Multiply the age of the dog by 7 to find the human equivalent age
human_age = int(dog_age) * 7
#The return type of input is a string(str)
print('As it is, the result of age x 7:',dog_age * 7)
#If you enter multiple character strings you want to output to the print function, a space will be inserted between them.
print('your dog',
dog_name,
'Human equivalent age',
human_age,
'I'm old')
Recommended Posts