Answer:
The answer to this question can be given as:
Statement:
number = int(line.strip())
Explanation:
In the above statement, we declare an integer variable number accept the integer value from the file that name is line. In this line, we use the strip() function. This function returns a duplicate string with both starting and tracking characters removed (based on the string parameter passed). The strip() function removes characters from both sides (left and right) based on the parameter(a string defining the collection of characters to be removed).
Answer:
num_guesses = int(input())
user_guesses = []
for i in range(num_guesses):
x = int(input())
user_guesses.append(x)
print(user_guesses)
Explanation:
This solution is provided in Python
This line prompts the user for a number of guesses
num_guesses = int(input())
This line initializes an empty list
user_guesses = []
This loop lets user input each guess
for i in range(num_guesses):
This line takes user input for each guess
x = int(input())
This appends the input to a list
user_guesses.append(x)
This prints the user guesses
print(user_guesses)
Answer:
Option a: a sorted array
Explanation:
Since the expectation on the data structure never need to add or delete items, a sorted array is the most desirable option. An array is known for its difficulty to modify the size (either by adding item or removing item). However, this disadvantage would no longer be a concern for this task. This is also the reason, linked list, binary search tree and queue is not a better option here although they offer much greater efficiency to add and remove item from collection.
On another hand, any existing items from the sorted array can be easily retrieved using address indexing and therefore the data query process can be very fast and efficient.
Answer:
I am doing it with python.
Explanation:
nums = '9 -8 -7 -6 -5 -4 -2 0 1 5 9 6 7 4'
myfile = open('data.txt', 'w')
myfile.write(nums)
myfile.close()
myfile = open('data.txt', 'r')
num1 = (myfile.read())
num1 = num1.split()
print(num1)
print(type(num1))
for x in num1:
x = int(x)
if x < 0:
minus = open('dataminus.txt', 'a')
minus.write(str(x) + ' ')
minus.close()
elif x>= 0:
plus = open('dataplus.txt', 'a')
plus.write(str(x)+' ')
plus.close()
get int input for a
get int input for b
get string input for operator
if a is not int or b is not int throw exception and print error
if operator is not * / // or % throw exception and print error
if operator is * do multiplication of a and b and make answer c
else if operator is / do division of a and b and make answer c
else if operator is // do floor division of a and b and make answer c
else if operator is % do floor modulo of a and b and make answer c
print c