Question

Write a python code that will ask the user to enter an integer number n. Construct...

Write a python code that will ask the user to enter an integer number n. Construct a recursive function that prints numbers 1 to n in the form “11223344..nn”.

Homework Answers

Answer #1

This problem can be solved by taking a variable that counts from 1 to n.

We print the variable twice, every time the function is called and then recall the fuction after incrementin the value.

NOTE : Take care of the indentation in the code using the screenshot.

CODE :


def recur(x,i):
i=i+1
print(i, end = '')
print(i, end = '')
if i<x:
recur(x,i)
  
x = int(input("Enter an integer : "))
i = 0
recur(x,i)

OUTPUT :

Enter an integer : 10
1122334455667788991010

Know the answer?
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
Similar Questions
IN PYTHON : Write a program that asks the user for a number. Write the number...
IN PYTHON : Write a program that asks the user for a number. Write the number to a file called total.txt. Then ask the user for a second number. Write the new number on line 2 with the total for both numbers next to it separated by a comma. Then ask the user for a third number and do the same. Keep asking for numbers until the person puts in a zero to terminate the program. Close the file. Be...
- Write a Python program which asks the user to enter a number, if the number...
- Write a Python program which asks the user to enter a number, if the number is divisible by 6 or 7, the program prints “The number X is divisible by 6 or 7” and if the number is neither divisible by 6 nor by 7, then it prints “The number X is not divisible by 6 and 7”.
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code.
Write a Python program that will ask the user to enter the masses of two particles...
Write a Python program that will ask the user to enter the masses of two particles (particle one and particle two) and particle 1’s initial velocity (v1). Assume particle two is at rest. The program should calculate the scattering angle and velocity for particle 2 as a function of the scattering angle and resulting velocity of particle 1
in c++ Write a C++ program that asks the user to enter an integer number and...
in c++ Write a C++ program that asks the user to enter an integer number and prints it back "vertically" to the screen. Use recursion in your solution. As an example of how the program will work: Please enter an integer: 12345 The integer you entered will print vertically as: 1 2 3 4 5
Write a MATLAB while-loop code that asks a user to enter an integer number until its...
Write a MATLAB while-loop code that asks a user to enter an integer number until its factorial is smaller than 100.
1. Write a code that asks the user to enter a sentence. Then process the sentence...
1. Write a code that asks the user to enter a sentence. Then process the sentence and let the user know which alphabets/numbers/symbols are used in the sentence and how many times. please use python
Write a mips assembly language program that asks the user to enter and integer number and...
Write a mips assembly language program that asks the user to enter and integer number and read it. Then ask him to enter a bit position (between 0 and 31) and display the value of that bit.
Write the C++ language statements to ask a user to enter a number within the range...
Write the C++ language statements to ask a user to enter a number within the range of 0 to 100 (0 and 100 are valid inputs). When the value is not valid, you should prompt the user to enter another value. (The user may enter many invalid numbers, so you must use loop). Only after the user enters a valid number should you display the message “Good” and the value of the number.
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The...
(SumDigits.java) Write code that asks the user to enter an integer between 100 and 999. The program finds and displays the three digits in the number. The program also calculates and displays the sum of the three digits. A sample run is shown below: Enter a number between 100 and 999: 528 The three digits in the number are: 5 2 8 The sum of the three digits is: 15 Note: You must use integer division and modulo division to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT