Partial supplement to list processing
list.py
#split function Splits the given data with the specified arguments and returns it as a list. I will not use it this time.
#random.randrange function Randomly retrieves from the elements of the list of arguments
import sys
import random
dice = []
for line in sys.stdin.readlines():
dice.append(line.rstrip())
#Value to be entered(Example)
1
2
3
4
5
6
#The numbers from 1 to 6 entered for each line are stored in the list of dice variables
num = len(dice)
print(dice[random.randrange(num))
#Any of the 0th 1 to 5th 6 of the contents of the dice is output.
Processing supplement for input
line = input (). rstrip () #rstrip function Look into the line feed code at the end of the character string.
import sys line = sys.stdin.readlines () # sys.stdin.readlines function file-Reads all input values on multiple lines and processes them line by line.
Recommended Posts