Question

Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function.

# Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input(Please prvide a

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

def display(a,b):
#while a not equal to b
while a!=b:
#print a
print(a)
#increment value of a
a = a+1
#print value of b at last
print(b)
#ask user value of a
a = int(input("Please provide a value for a: "))
#ask user value of b
b = int(input("Please provide a value for b: "))
#call function display with a and b value
display(a,b)

Screenshots -

Please provide a value for a: 10 Please provide a value for b: 30 10 11 12 13

Add a comment
Know the answer?
Add Answer to:
Implement a Python function that prints integers from a to b. The main part of the...
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
  • For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the...

    For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...

  • Implement a Python function called revd that takes a chain of characters and returns a new...

    Implement a Python function called revd that takes a chain of characters and returns a new chain with the double of the elements but in reverse order. In the main program, ask the user to input the chain of characters, call the function and display the result Example : Please enter a chain of characters: abcd ddccbbaa NOTE: This is a repost. Please DO NOT use GLOBAL Variables

  • Part 1 Below you are given the algorithms for two functions, main and doMath. Implement both...

    Part 1 Below you are given the algorithms for two functions, main and doMath. Implement both in Python. function main(): get x from user get y from user call doMath(x,y) function doMath(lhs, rhs): sum = lhs + rhs diff = lhs – rhs product = lhs x rhs quotient = lhs / rhs display sum, diff, product, and quotient on separate lines Part 2 Add a new function called get_fuel to your Python program. calc_fuel which takes two input parameters:...

  • Python: Create a function count_target_in_list that takes a list of integers and the target value then...

    Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...

  • PYTHON Create a function called squareValue. squareValue will calll the function getValue() to square the value...

    PYTHON Create a function called squareValue. squareValue will calll the function getValue() to square the value and return it back to the main portion of the program. In main call squareValue which will call getValue. def getValue():     val = int(input("Enter a number"))     return val myValue = getValue() print("The value entered is ", myValue)

  • In python, Implement a function studentID() which allows the user to enter the 7-digit student ID....

    In python, Implement a function studentID() which allows the user to enter the 7-digit student ID. The program will keep prompting the user for a last name and first name. If the student does not have a student ID on record, the program will then ask for the student ID, and store that information. If the student already has a student ID, the program will display it, and ask for confirmation whether a new studentID should be assigned (and, if...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • Python program Use the provided shift function to create a caesar cipher program. Your program s...

    python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

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
ADVERTISEMENT