Assignment Content
You recently graduated from college and are applying for a programming job that requires the understanding of loops in Python. The manager you are interviewing with has asked you to take an assessment to prove your programming knowledge. Below are the requirements for the programming skills test.
In Python, create a program that meets the following requirements:
Provide the code and take a screenshot of the output. Then, paste the screenshot(s) into a Microsoft® Word document. PLEASE CODE IN PYTHON
Code:
p, q = input("Enter two Integers: ").split() #taking two input together
# You can also take input one by one
#p = input("Enter First Integer")
#q = input("Enter Second Integer")
x=int(min(p,q)) #taking minimum value out of two variables p and q
y=int(max(p,q)) #taking maximum value between p and q
#1st part
print("First loop")
for i in range(x,y,2):
print(i,end=" ")
#2nd part
#For 2nd part you didn't mention condition for the loop and even by what value you
#want to increment so I am assuming the condition is same as above for loop
print("\n")
Z=0
print("Second loop")
for i in range(x,y,2):
Z = x + y
print(Z,end=" ")
#note: Syntax of range: range(start,stop,step) wherein the step
#I have initialized 2 because you want to count x to y by 2's
Output:
The value of Z never changes because we didn't change the value of variable x and y, so that's why every time loop iterate it prints 13 each time
Get Answers For Free
Most questions answered within 1 hours.