Python3 is completely free on Paiza, so I summarized it.
lesson.py
'''
if conditional expression:
#Processing when the conditional expression is satisfied
'''
number=1
if number == 1:
#If the left side is equal, distinguish it from substitution
print("Love!")
lesson.py
number=2
if number == 1:
#If the left side is equal, distinguish it from substitution
print("Love!")
Nothing is displayed
lesson.py
number=2
if number == 1:
#If the left side is equal, distinguish it from substitution
print("Love!")
else:
#Processing when the conditional expression is not satisfied
print("I hate you!")
It is displayed as "Kirai"
lesson.py
#Randomly display likes and dislikes
import random
number=random.randint(1,2)
if number == 1:
#If the left side is equal, distinguish it from substitution
print("Love!")
else:
#Processing when the conditional expression is not satisfied
print("I hate you!")
lesson.py
#Conditional branch by if statement
import random
number = random.randint(1, 3)
print("Your ranking is" + str(number) + "Is the place")
#Add an if statement here
if number ==1:
print("Congrats")
lesson.py
#Conditional branch by if statement
import random
number = random.randint(1,5)
print("Your ranking is" + str(number) + "Is the place")
#Add an if statement here
if number == 1:
print("Congrats")
else:
print("A little after")
lesson.py
#Conditional branch by if statement
import random
number = random.randint(1, 3) * 100
print("Your score is" + str(number) + "Is the point")
if number == 300:
print("Congrats")
lesson.py
# coding: utf-8
#Conditional branch by if statement
import random
number = random.randint(1,3) * 100
print("Your score is" + str(number) + "Is the point")
if number == 300:
print("Congrats")
else:
print("Zannen")
How to use two or more conditional expressions? → Use elif
lesson.py
#Conditional branch by if statement elif statement
number = 1
if number == 1:
print( "Love!") #Processing when the conditional expression is satisfied
elif conditional expression 2:
#Processing when conditional expression 2 is satisfied
else:
print( "I hate you") #Processing when the conditional expression is not satisfied
Write a conditional branch "neither" in elif
lesson.py
#Conditional branch by if statement elif statement
number = 2
if number == 1:
print( "Love!") #Processing when the conditional expression is satisfied
elif number == 2;
print("Neither")#Processing when conditional expression 2 is satisfied
else:
print( "I hate you") #Processing when the conditional expression is not satisfied
lesson.py
# coding: utf-8
#Conditional branch by if statement
import random
number = random.randint(1, 5)
print("Your ranking is" + str(number) + "Is the place")
#Add an if statement here
if number==1:
print("Congrats")
elif number==2:
print("A little after")
else :
print("You did your best")
There were many typographical errors
lesson.py
#Conditional branch by if statement
import random
number = random.randint(1, 5)
print("Your ranking is" + str(number) + "Is the place")
if number == 1:
print("Congrats")
elif number == 2:
print("A little after")
else:
print("You did your best")
lesson.py
a == b :a is equal to b
a > b :a is greater than b
a < b :a is less than b
a >= b :a is more than b
a <= b :a is less than or equal to b
a != b :a is not equal to b
lesson.py
number = 2
if number > 1:
print("Love!") #Processing when the conditional expression is satisfied
.lesson.py
#Conditional branch by if statement Comparison operator
time = 12
if time > 1:
print("in the morning") #Processing when the conditional expression is satisfied
elif time ==12:
print("noon!")
elif time >12:
print("afternoon")
lesson.py
import random
age = random.randint(18, 22) #How old are 18 in age~Randomly assigned in the range of 22
text = ""
if age>= 20:
text = "Drinkable" #Processing when the condition is met
#Processing when the condition is met
else:
text = "No drinking" #Processing when it was not
#Processing when it was not
print(str(age) + "Talent" + text)
lesson.py
# coding: utf-8
import random
place = random.randint(1, 12) #1 to place~Randomly assigned at 12
print(str(place) + "Rank", end="")
if place <= 6:
print("Winning") #Processing when the condition is met
else:
print("Out of winning area") #Processing when it was not
lesson.py
import random
age = random.randint(15, 25) #How old are 15 in age~Randomly assign in the range of 25
print(str(age) + "Talent", end="")
if age >= 20:
print("I'm an adult") #Processing when the condition is met
else:
print("I'm a minor") #Processing when it was not
lesson.py
import random
omikuji = random.randint(1,10)
print(omikuji)
if omikuji ==1:
print("Daikichi")
elif omikuji ==2:
print("Nakayoshi")
elif omikuji <=4:#3,4
print("Kokichi")
elif omikuji <=7:
print("Bad") #5,6,7
else:
print("Great villain")
In omikuji, numbers from 1 to 100 are random It will be substituted.
When the number of omikuji is 30 ~ 100, it is displayed as "Omikuji's contents are XX, so Daikichi". When the number of omikuji is 29 or less, it is displayed as "Omikuji's contents are XX, so it's a terrible thing."
lesson.py
import random
omikuji = random.randint(1, 100)
if omikuji >=30:
print("The contents of omikuji" + str(omikuji) + "So Daikichi")
else:
print("The contents of omikuji" + str(omikuji) + "So it ’s a villain")
lesson.py
import random
hit =random.randint(1,10)
#print(hit)
if hit < 6 :
print("To slime" + str(hit) + "Damaged")
else:
print("critical hit!Inflicted 100 damage on slime!")
lesson.py
#Find the year from the year
import datetime
seireki=2015
#seireki=atetime.date.today().If year, it will be the number subtracted from the present
print("Year" + str(seireki)+ "Year is",end="")
#Calculate the year from the year
#The year of Heisei is 1989. The difference is 1988
#Year- 1988 =Heisei*Year
#Example:Year 1989- 1988 =Heisei 1
#Example:Year 2015- 1988 =2015
heisei = seireki -1988
print("Heisei"+str(heisei) +"Year")
lesson.py
#Convert the Christian era to Showa
import random
seireki = random.randint(1926, 1988) #Year
print("Year" + str(seireki) + "Year is", end = "")
#Showa year is calculated
showa = seireki-1925
#Showa year is output
print("Showa" + str(showa) + "Year")
lesson.py
#Convert the Christian era to Reiwa
import random
ad_year = random.randint(2019, 2099) #Year
print("Year" + str(ad_year) + "Year is", end = "")
#Calculate Reiwa year
era_year = ad_year-2018
#Output Reiwa year
print("Reiwa" + str(era_year) + "Year")
Recommended Posts