Question

Give the solution using Python programming for following with explanations: a. Take two numbers and display which number is p
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1)

a)

CODE:

# take to user from user
a = int(input("1st number: "))
b = int(input("2nd number: "))
# check if a is greater tha zero or not
if a > 0:
    print("%d is positive" % a)
else:
    print("%d is negative" % a)
# check if b is greater tha zero or not
if b > 0:
    print("%d is positive" % b)
else:
    print("%d is negative" % b)

# take to user from user a = int(input(1st number: )) b = int(input(2nd number: )) # check if a is greater tha zero or no

OUTPUT:

Ist number: 4 2nd number: -8 4 is positive -8 is negative

b)

CODE:

# take to user from user
dividend = int(input("Dividend: "))
divisor = int(input("Divisor: "))
# divide it and get quotient
print("Quotient: %f" % (dividend / divisor))
# use mod(%) to get the remainder
print("Remainder: %d" % (dividend % divisor))

Р м м ы # take to user from user dividend = int(input(Dividend: )) divisor = int(input(Divisor: )) # divide it and get qu

OUTPUT:

Dividend: 5 Divisor: 2 Quotient: 2.500000 Remainder: 1

c)

CODE:

# take two numbers from user
a = int(input("1st number: "))
b = int(input("2nd number: "))

# checking if a is equal to b or not
if a == b:
    print("Same")
else:
    print("Not same")

E # take two numbers from user a = int(input(Ist number: )) b = int(input(2nd number: )) N сш в uл o # checking if a is e

OUTPUT:

1st number: 5 2nd number: 5 Same

Q2)

Python variable naming rules are as follows:

  • A variable name should start with an underscore character or any letter only.
  • It can't start with a number or any other character.
  • A variable name can only have letters, numbers, and _(underscore).
  • All variables are case-sensitive.

Q3)

CODE:

a = 0
b = 1
print(a, end=" ")
print(b, end=" ")
# running till 14 because on index 15 the value exceeds 900
for i in range(14):
    c = a + b
    print(c, end=" ")
    a = b
    b = c

ooo vau HD w NW b = 1 print(a, end= ) print(b, end= ) # running till 14 because on index 15 the value exceeds 900 for i i

OUTPUT:

8112358 13 21 34 55 89 144 233 377 616

Q4)

# n need to be defined
n=20
# instead of z y must be used
y = 0
i = 5.0
# iterating from 5 to less than equal to n
for i in range(5, n + 1, 10):
    # capital I replaced with small i
    y = y + 8 / i
    print(y)

# n need to be defined n=20 # instead of zy must be used y = 0 i = 5.0 # iterating from 5 to less than equal to n for i in ra

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.

Add a comment
Know the answer?
Add Answer to:
Give the solution using Python programming for following with explanations: a. Take two numbers and display...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Programming 4th Edition Write a program using for loop to display numbers 1 through 5

    Python Programming 4th Edition Write a program using for loop to display numbers 1 through 5

  • Write the PYTHON code that displays the following numbers: The program should have a header that...

    Write the PYTHON code that displays the following numbers: The program should have a header that displays "Number   Doubled Tripled" above the start of the numbers. If putting all numbers on the same line, then they will need to be separated so you can see he individual number.(https://www.programiz.com/python-programming/methods/built-in/print) The program should display Every whole number from 1 through 35. The program should display that number doubled. The program should also display that number tripled. Make a working version of this...

  • Spring 2020 CSCI 2450: HW5 (Programming Assignment (10 points) Answer any ONE of the following problems....

    Spring 2020 CSCI 2450: HW5 (Programming Assignment (10 points) Answer any ONE of the following problems. If you answer both of them, you will get bonus points. Use any instructions and Irvine procedures we covered till now. These problems might require instructions from chapter 07. Problem 1: Greatest Common Divisor ( GCD) Greatest Common Divisor (GCD): The greatest common divisor (GCD) of two integers is the largest integer that will evenly divide both integers. The GCD algorithm involves integer division...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • You recently graduated college and you are applying for a programming job that requires the understanding...

    You recently graduated college and you 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: Take two integers from the user. Save the lower number as x. Save the largest integer as y. Write a loop that counts...

  • You recently graduated college and you are applying for a programming job that requires the understanding...

    You recently graduated college and you 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: Take two integers from the user. Save the lower number as x. Save the largest integer as y. Write a loop that counts...

  • Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...

    Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...

  • Programming Language is Java Lab 1: Programming Exercises Input/Process/Output 1) Run the Numbers. Write a program...

    Programming Language is Java Lab 1: Programming Exercises Input/Process/Output 1) Run the Numbers. Write a program with two input values. The program should display the sum, difference, quotient, product, and average of the two numbers. 2) Jake’s Problem. Jake has a car with an 8-gallon fuel tank. Jake fills his tank with gas and drives 60 miles to a friend’s house. When he gets to his friend’s house, he has 6 gallons left in his fuel tank. Write a program...

  • PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random...

    PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20

  • USING PYTHON *Write a program, in which the user enters two numbers, then divides the first...

    USING PYTHON *Write a program, in which the user enters two numbers, then divides the first number by the second, and prints the result to two decimal places. *Make sure that that the inputs are floats (with exception handling using the ValueError). *Make sure that there is no divide by zero error (with exception handling). *Then have a plain exception: That handles any other error. -Thank you in advance for your assistance-

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT