Python3 is completely free on Paiza, so I summarized it.
lesson.py
'''
for counter variable in repeat range
Iterative processing
'''
#Counter variable: A variable for work that stores data to be repeated
#Be sure to indent iterative processing
for i in range(5):
print("hello world" + str(i))
for i in range(6,11):#6,7,8,...End at 11
print("hello world" + str(i))
#→ 6 to 10 are displayed
print("last"+str(i))
#is displayed as last10
lesson.py
for i in range(5):
print("Hello, paiza learning")
lesson.py
for i in range(16):
print(i)
for i in range(1,13):
print(str(i) + "Moon" )
lesson.py
i=1#Initialize counter variable
while i<=10: #1,2,3...11 Repeated until the while conditional expression is satisfied
print(i) #Iterative processing
i = i + 1 #Update counter variable
print("next" + str(i))
print("last"+str(i))
lesson.py
i=1#Initialize counter variable
while i<=4:
print("Hello, paiza learning") #Iterative processing
i = i + 1 #Update counter variable
lesson.py
i=0#Initialize counter variable
while i<=5: #1,2,3...Repeated until the while conditional expression is satisfied
print(i) #Iterative processing
i = i + 1 #Update counter variable
lesson.py
#Counter variable "i= i+Without "1", it will be an "infinite loop" and time out.
i = 5#Initialize counter variable
while i <= 15:
print(i)#Iterative processing
#Update counter variable
print("last:" + str(i))
lesson.py
#Change how to write counter variables "i"+=1」
i = 5#Initialize counter variable
while i <= 15:
print(i)#Iterative processing
i += 1#Update counter variable
print("last:" + str(i))
lesson.py
#Change how to write counter variables "i"-=1」
#Operator to reduce inequality sign "while i">=Change to 1 "
#From 10 to 1
i = 10#Initialize counter variable
while i >= 1:
print(i)#Iterative processing
i -= 1#Update counter variable
print("last:" + str(i))
lesson.py
#Attack slime
#Damage is random from 1 to 10
#Repeat until the slam's HP reaches 0
import random
hp=30
while hp > 0:
hit = random.randint(1,10)
print("To slime" + str(hit) + "Damaged!")
hp -=hit
print("Defeated slime")
An output program that displays numerical values line by line from 1.5 to 15.
lesson.py
i = 5#Initialize counter variable
while i <= 15:
print(i)#Iterative processing
i += 1#Update counter variable
i = 5 #Initialize counter variable
while i >= 1:
print(i)#Iterative processing
i -= 1#Update counter variable
Display even numbers from 3.1 to 10
i = 2 #Initialize counter variable
while i <= 10:
print(i)#Iterative processing
i += 2#Update counter variable
lesson.py
#Automatic generation of HTML tags
#I have to repeat!
print("<select name=\'age\'>")
print("<option>1 year old</option>")
print("<option>2 years old</option>")
print("<option>3 years old</option>")
print("</select>")
#Use the for statement in such a case
print("<select name=\'age\'>")
for age in range(10):
print("<option>"+ str(age+1) + "Talent</option>")
print("</select>")
#range with range function(10)Will be output from 1 to 9
・
lesson.py
print("<ul>")
print("<li>1</li>")
print("<li>2</li>")
print("<li>3</li>")
print("</ul>")
#Iterative processing of for statement
print("<ul>")
for age in range(100):
print("<li>"+ str(age+1) + "</li>")
print("</ul>")
・ Program flow
Enter data
↓
Processed programmatically
↓
Output the result
・ Types of data entry
----------------------
Web service/API
Database
File
Specified when executing the keyboard
----------------------
↓ Input
Program execution
・ What is standard input?
Originally how Unix works
----------------------
File
keyboard
Specified at runtime
----------------------
↓
Standard input
↓
Program execution
What is standard input </ strong> Originally, it is a mechanism prepared by Unix-like OS such as LINUX. If you create a program that supports standard input, you can switch the input destination, such as reading a file, reading data from the keyboard, or specifying parameters when the program is executed.
input () function </ strong> Read one line from standard input
lesson.py
input
paiza
line=input()
print("hello" + line)
output
hellopaiza
lesson.py
input
123
#Add int for numbers
line=int(input())
print(line*10)
output
1230
lesson.py
input
Hello Paisa
string=input()
print(string)
Output Hello Paiser
lesson.py
input
1234
line=int(input())
print(line*100)
output
123400
lesson.py
input
paiza
python
line = input()
print("hello " + line)
line = input()
print("hello " + line)
output
hello paiza
hello python
#I want to input multiple lines as standard
input
3
paiza
python
world
count=int(input())
print("Number of data" + str(count))
for i in range(count):
line = input ().rstrip()
#Delete line endings of data with rstrip
print("hello " + line)
output
Number of data 3
hello paiza
hello python
hello world
rstrip () function </ strong> Remove line breaks at the end of lines of data. If line breaks remain, it may adversely affect the subsequent processing, so it is deleted here. You can remove the line break in the return value of the input by writing it after the input and following the dot.
lesson.py
input
4
Brave
Warrior
merchant
Wizard
count=int(input())
print("Number of data" + str(count))
for i in range(count):
line = input ().rstrip()
print(line + "Attacked the slime")
output
Number of data 4
The brave attacked the slime
The warrior attacked the slime
The merchant attacked the slime
The wizard attacked the slime
lesson.py
input
8
count=int(input())
for i in range(count):
print("There was a slime")
output
There was a slime
There was a slime
There was a slime
There was a slime
There was a slime
There was a slime
There was a slime
There was a slime
lesson.py
input
5
12
#Standard input and loop processing
num1 = int(input())
num2 = int(input())
for i in range(num1, num2 + 1):
print(i)
5
6
7
8
9
10
11
12
lesson.py
for seireki in range(1989,2017):
print("Year"+ str(seireki) +"Year", end=" ")
heisei = seireki -1988
print("Heisei"+ str(heisei)+"It's the year.")
output
1926 AD is 1926
1927 AD is 1927
:
:
1988 AD is 1988
lesson.py
for seireki in range(1926,1989):
print("Year"+ str(seireki) +"Year is",end="")
heisei = seireki -1925
print("Showa"+ str(heisei)+"Year")
lesson.py
input
1975
10
start = int(input())
term = int(input())
for seireki in range(start, start + term):
print("Year" + str(seireki) + "Year is", end = "")
shouwa = seireki - 1925
print("Showa" + str(shouwa) + "Year")
output
1926 AD is 1926
1927 AD is 1927
:
:
1987 is 1987
Recommended Posts