Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hey guys, i am having trouble with these projects and any help would be apprecia

ID: 3924798 • Letter: H

Question

Hey guys, i am having trouble with these projects and any help would be appreciated. The language required is Python. Thanks in advance,

1. Write a program that asks the user to enter two numbers a and b. Then, the program calculates the sum of all odd numbers between a and b (inclusive). You need to call the input function twice the get a and b. You need to write this program using a while loop. 2. Write a program that asks the user to enter two numbers a and b, and prints all positive numbers that are divisible by a and are less than b. For example, if b is 100 and a is 10, print 10 20 30 40 50 60 70 80 90. 3. Write a program that asks the user for 5 numbers (one at a time) and prints the square root of the number.

Explanation / Answer

# python code
import math

# program 1
a = int(raw_input("Input a: "))
b = int(raw_input("Input b: "))
sum = 0
start = a
while start <= b:
   if start%2 == 1:
       sum = sum + start
   start = start + 1
print "Sum: ", sum
print " "

# program 2
a = int(raw_input("Input a: "))
b = int(raw_input("Input b: "))
sum = 0
start = a
while start < b:
   if start%a == 0 and start > 0 and start < b:
       print start,
   start = start + 1
print " "

# program 3
for i in xrange(0,5):
   number = float(raw_input("Input number: "))
   print "Square root: ", math.sqrt(number)

'''
output:

Input a: 1
Input b: 10
Sum: 25


Input a: 10
Input b: 100
10 20 30 40 50 60 70 80 90

Input number: 23
Square root: 4.79583152331
Input number: 12
Square root: 3.46410161514
Input number: 16
Square root: 4.0
Input number: 20
Square root: 4.472135955
Input number: 25
Square root: 5.0

'''