This is a notebook I made for my study.
last week "Introduction to Programming Language Python 3" https://www.udemy.com/intro-to-python3/ I've finished up to Section 2. However, I stumbled on the way and decided to stop.
Instead, I decided to do paiza learning. https://paiza.jp/works
This was to actually devote programming to video learning and exercises without doing troublesome things such as environment construction.
In a week, I finished the python beginner's course and learned a lot about what I didn't understand.
・ I don't understand "input".
In paiza, there are places to input and output, and when you input to the input place and execute it, the output result is displayed.
a = input() print(a)
Input value sample Output value sample
data = input() print(data)
Input value 1 2 3 Output value 1 2 3
import sys for line in sys.stdin.readlines(): print(line.rstrip)
Input value 1 2 3
Output value 1 2 3
I wasn't sure why this happened, but apparently the sys.stdin.readlines function reads the file and processes it line by line, so it's like this.
Next, I will give the total value for development
num = [20,30,40,60]
print(sum(num))
The output value is 150.
Let's do this with the one-line and multi-line numbers.
~~ I tried it, but I can't do it yet. ~~
~~ I will post it if possible. ~~ (2/6 was done!) I'm not sure about numbers, arrays, and type transformations right now.
line = input() print(line)
Input value 1 2 3 Output value 1 2 3
I understand that
line = input().split() print(line)
Input value 1 2 3 Output value ['1', '2', '3']
You can see this too. You made it into an array, didn't you?
Output value [1,2,3] How do you do it?
line = input().split()
line_int = list(map(int,line))
print(line_int)
The output value is now [1,2,3]! !!
Apparently, the map function and the list function were the key.
The map function "processes all elements". It is not well understood.
I don't really understand the list function.
I will check it from time to time.
So the total is
print(sum(line_int))
Recommended Posts