Question

In: Computer Science

This program is written by Ruby and Please rewrite this program as python. input_lines = gets.split("...

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)

Solutions

Expert Solution

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.


Related Solutions

Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the...
Python - Rewriting a Program Rewrite Program 1 using functions. The required functions are in the table below. Create a Python program that will calculate the user’s net pay based on the tax bracket he/she is in. Your program will prompt the user for their first name, last name, their monthly gross pay, and the number of dependents. The number of dependents will determine which tax bracket the user ends up in. The tax bracket is as follows: 0 –...
This program (in python) will display a set of authors and the number of novels written...
This program (in python) will display a set of authors and the number of novels written by each author in both a table and a histogram. You will ask the user for all of the information. Using what you learned about incremental development, use the following approach to create your program: Prompt the user for the information about the table. First, ask for the title of this data set by prompting the user for a title for data. Output the...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then calculates the arithmetic mean (otherwise known as the average), the median (that is, the number that splits the set of value in half with half being above and half being below the number), and the standard deviation (that is, the average of distance each number is from the mean then squared). Further information about these calculations can be found here: average: http://en.wikipedia.org/wiki/Average (add up...
Must be done in Ruby Histogram Create a Ruby program which reads a string of information...
Must be done in Ruby Histogram Create a Ruby program which reads a string of information and uses a Hash to keep track of letter frequencies and then displays a Histogram using this frequency information. IN ORDER TO RECEIVE FULL CREDIT, YOUR CODE SHOULD PROPERLY PROCESS THE STRING INFORMATION, COUNTING FREQUENCIES BY USING A HASH. A number of different program dialogues describe the program I am looking for. Enter Data: supercalifragilisticexpialadocious A - 4 - **** C - 3 -...
PLEASE WRITE IN C++ PROGRAM THANKS - QUEUES Please study the code posted below. Please rewrite...
PLEASE WRITE IN C++ PROGRAM THANKS - QUEUES Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max capacity using namespace std; /** Queue structure definition */ struct QueueType { int data; struct...
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template....
Please write a C++ program. Please rewrite your Array (including the operator overloading) into a template. And rewrite your main function to test your template for integer array and double array. Following is my complete code: #include <iostream> using namespace std; class Array { private: // Pointer to memory block to store integers int* data; // Maximum size of memory block int cap; // Stores number of integers in an array int num; public: // Constructor Array(int size); // Default...
The clause below was written by the seller. You are the buyer. Rewrite it so it...
The clause below was written by the seller. You are the buyer. Rewrite it so it is to your advantage. Delivery; Title; and Risk of Loss. Unless otherwise stated in Exhibit A, the Seller shall deliver the Goods FOB the Seller’s facility and title to and risk of loss of the Goods will pass to the Buyer upon such delivery by the Seller. Any stated delivery dates are approximate. The Seller will not be liable for any losses, damages, penalties,...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
Python 3 A program will be written that outputs various geometric shapes, rendered in characters, line-by-line...
Python 3 A program will be written that outputs various geometric shapes, rendered in characters, line-by-line using nested loops. Here is what you need to know: 1- Copy this and don't change the inputs in the provided code: # Get the size and drawing character from the user size = input('Please enter the size: ') # Validate the input, exit if bad if size.isdigit(): size = int(size) else: print("Exiting, you didn't enter a number:", size) exit(1) # Input the drawing...
create a file with 1000 alphanumeric ones written one per line. Write a program in python...
create a file with 1000 alphanumeric ones written one per line. Write a program in python that randomly selects 100 of them, holds the index of each alphanumeric, adds the hash of the previous 100 and tries to find a random alphanumeric so that if it adds it to the list of indicators the SHA256 of the whole to have 10 zeros at the end. You start with the original Hash: 1111..111 my solution so far: import random import string...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT