In: Computer Science
This program is written by Ruby and Please rewrite this program as python.
input_lines = gets.split(" ") tasizan = input_lines[0].to_i hikizan = input_lines[1].to_i cnt=-0 drill=[] while cnt<tasizan kazu1 = rand(100) kazu2 = rand(100) next if kazu1+kazu2>99 next if drill.include?("#{kazu1} + #{kazu2} =") drill.push("#{kazu1} + #{kazu2} =") cnt+=1 end cnt=0 while cnt<hikizan kazu1 = rand(100) kazu2 = rand(100) next if kazu1 <= kazu2 next if drill.include?("#{kazu1} - #{kazu2} =") drill.push("#{kazu1} - #{kazu2} =") cnt+=1 end puts drill.sample(tasizan+hikizan)
import random #random package
tasizan=0 #taking variables with initial value 0
hikizan=0
input_lines = input() #taking input
input_lines = input_lines.split(" ") #splitting input to list
if len(input_lines)>0: #if list has an element
tasizan = int(input_lines[0]) #storing 1st value in
tasizan
if len(input_lines)>1: #if list has more than 1 element
hikizan = int(input_lines[1]) #storing 2nd value in
hikizan
cnt=0 #count
drill="" #drill is a string for different data types
while cnt<tasizan: #while loop iterates until cnt is equal to
tasizan
kazu1 = random.randint(0, 100) #random integer
kazu2 = random.randint(0, 100)
if (kazu1+kazu2)>99:
continue #continue to next
iteration
else:
drill=drill+str(kazu1)+" +
"+str(kazu2)+" =\n" #storing new string to drill
cnt+=1
cnt=0
while cnt<hikizan:
kazu1 = random.randint(0, 100)
kazu2 = random.randint(0, 100)
if kazu1 <= kazu2:
continue
else:
drill=drill+str(kazu1)+" -
"+str(kazu2)+" =\n"
cnt+=1
print(drill)
If you have any doubt comment me.