Python3 command line arguments; there are unknown number of arguments, 'only number // number and the length of the argument is three' is a valid argument,for example,2//5,3//5 are valid arguments,a//2,b//4,7//0,b//k are not valid arguments, calculate each valid argument and the number of valid arguments, and then print
hint: split is very useful
restrictions: [1:], for loop, slicing, lambda function, 'in' keyword,isdigit(), isalpha() cannot be used. Exception handling must be used, it is recommended to use while loop to solve this problem.
Here is the answer...
CODE:
import sys
def find(s):
i=0
#print(s)
while(i<len(s)):
if s[i]=='/':
return i
i+=1
def join(l):
i=0
s=""
while(i<len(l)):
s+=l[i]+" "
i+=1
return s
length=len(sys.argv)
sys.argv=join(sys.argv)
a=sys.argv.split(" ")
#print(a)
index=1
l=[]
while(index<length):
l.append(a[index]) #append each argument to list
index+=1
j=0
count=0 #to take 3 number// number
valid=0 #for valid count
while(j<len(l)): #iterate through list of numbers
i=0
#print(l[j])
k=find(l[j]) #find the // operator in argument
#print(k)
if(count==3): #if count 3 break
break
s1="" #for storing first number
while(i<k):
s1+=l[j][i] #concatenate to string
i+=1
i+=2
#print(i)
s2="" #for denominator/second number
while(i<len(l[j])):
s2+=l[j][i] #concatenate to second string
i+=1
#print(s1,s2)
j+=1 #for next argument
try:
a=int(s1) #convert first number to integer
b=int(s2) #convert second number to integer
#print(a,b)
count+=1 #count the number//number arguments
#if possible then print and count valid arguments
print(a,"//",b," = ",a//b)
valid+=1
except:
print(end="") #cathing the raised exception and do nothing
print("There are ",valid," valid arguments") #print valid
arguments
CODE Snapshot:
OUTPUT:
If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP....
Python3 command line arguments; there are unknown number of arguments, 'only number // number and the...
Python3 please use while loop to solve this question,specific
information is on the graph
Question 2 - 15 marks Write the function read_file_center50 (filename). The function returns a list of 50 strings that are at the center of the file. A file has n lines, then is the center. A list of length 50 is returned, where the first line is 25 and the last line is 2 + 25. If the file has n < 50 lines, then only...
Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have two required arguments and two keyword arguments. The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5. Test it twice from...
Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have two required arguments and two keyword arguments. The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5. Test it twice from...
Your task is to write a C++ program that consumes integer values as command line arguments and returns the arithmetic mean of these values. To increase the flexibility of the program, there should be no set number of arguments. To overcome this, we will require the argument argv[1] to be the number of integers the user enters. For example, if the user wants to calculate the arithmetic mean of 4 numbers, they would pass in 4 as the first argument...
Problem 3 Rewrite Program 2. This is you must use keyword arguments to pass number of kWh and customer type to the bill_calculator function when it is called. Save your Python program in a file named Lab07P3.py. Submit the file to Blackboard for credit.This is what i wrote for prgram 2:(): kwh = (()) cus = (()) cus.upper() bill_calculator(kwhcus) (kwhcus): kwh <= cus == : price = kwh * kwh > cus == : price = * + ((kwh - ) * ) kwh <= cus == : price = kwh * kwh > cus == : price = * + ((kwh - ) * ) (.format(price))
how to write this code in python?
please don't print the space for each row last number.
Pascal's Triangle Pascal's Triangle is a number pattern with many interesting and useful properties. For example: Each number in the triangle is the sum of the two numbers above it. The number at row n and column k is equal to the binomial coefficient () "n choose k." 1 21 133 1 1 4 6 4 1 Write a program that prints Pascal's...
Python3 : question about object-oriented programming, Please
write program in the template(critter.py),specific information is
on the graphs
the missing words in the 4th line are 'To save an attribute,
attach it to this self keyword'
W11 - Critters Implement the Critter class. Each critter C has attributes species, size, and age The constructor accepts arguments for the attributes above, in the order above. You can expect size and age to be numeric values Each critter C has a can_eat) method,...
C++ Program Your program should: 1) Validate that the number of commandline arguments, after a.out is in the range [1,6]. If not, print an error message and stop the program with exit code 1. 2) Declare a vector of ints or array of ints to store the arguments. Use a loop to parse all the arguments (except a.out) into your vector/array. 3) Use a loop to calculate the greatest number (maximum). If the maximum is greater than 100, print "XNN"...
Python3, write a program, specific information is in the graphs,
I got 7 marks out of 10, you may change my codes to let it gives
correct output,restrications are also on the graph, for loop, in
key word, enumerate,zip,slices, with key word can't be used. All
the information is on the graph, is_shakespeare_play(line) may be a
function given that can check whether is Shakespeare play
Question 2- 10 marks Write the function keep titles short (filename, max charactars) which takes...