Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
Chapter 6, Problem 7PE
Program Plan Intro
Calculate the nth Fibonacci number
Program plan:
- Import the required packages
- The function named “fibonacci()” is defined and inside the “fibonacci()”,
- Declare the required variables named as “x”, “y” and “z”.
- Initialize a for loop to calculate and assign the value of the variables.
- Return the value stored in the “y” variable.
- In the “main()” function,
- Generate a prompt to take the user input.
- Call the method named “fibonacci()” with user input as the argument.
- Print the output statement and output value.
- Call the function “main()”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
*You need to use at least one user define function
Write a program to find the first n numbers of the Fibonacci series. You have to take a positive number from input and show all the Fibonacci numbers belongs to that range. If the number is not valid then notify the user and ask to input positive number again. If valid, then print the series.
Input: Key in a number: 10 Output: Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 Do you want to continue (y/n)? n Good bye!!
Language:(C programming)
***in python only***
use turtle function
Define the concentricCircles function such that:
It draws a series of concentric circles, where the first parameter specifies the radius of the outermost circle, and the second parameter specifies the number of circles to draw.
The third and fourth parameters specify an outer color and an other color, respectively. The outer color is used for the largest (i.e., outermost) circle, and then every other circle out to the edge alternates between that color and the 'other' color.
The difference between the radii of subsequent circles is always the same, and this difference is also equal to the radius of the smallest circle. Put another way: the distance between the inside and outside of each ring is the same.
Define concentricCircles with 4 parameters
Use def to define concentricCircles with 4 parameters
Use any kind of loop
Within the definition of concentricCircles with 4 parameters, use any kind of loop in at least one place.
Call…
Assignment
Write a program to calculate n! for a given number n and perform the simple calculator
operations. The valid operations
of the calculator are:
+ add
- sub
* mul
I div
The program must contain a function fact with one input parameter that returns the factorial of a
number, a function add that performs the addition of two numbers, a function sub that performs
the subtraction of two numbers, a function mul that performs the multiplication of two numbers,
a function div that performs the division of two numbers. The program must also check for bad
input data.
Make sure when you pass parameters you pass the addresses (not the value).
• All function return type must be of type void.
• Take inputs in main function.
• Pass the addresses of the operands and the address of the result to each function.
Output must be displayed as follows:
1: Addition
2: Subtraction
3: Multiplication
4: Division
5: Factorial
6: Quit
Enter the choice => 1
Enter two numbers => 2, 3
Sum => 5
Chapter 6 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 6 - Prob. 1TFCh. 6 - Prob. 2TFCh. 6 - Prob. 3TFCh. 6 - Prob. 4TFCh. 6 - Prob. 5TFCh. 6 - Prob. 6TFCh. 6 - Prob. 7TFCh. 6 - Prob. 8TFCh. 6 - Prob. 9TFCh. 6 - Prob. 10TF
Ch. 6 - Prob. 1MCCh. 6 - Prob. 2MCCh. 6 - Prob. 3MCCh. 6 - Prob. 4MCCh. 6 - Prob. 5MCCh. 6 - Prob. 6MCCh. 6 - Prob. 7MCCh. 6 - Prob. 8MCCh. 6 - Prob. 9MCCh. 6 - Prob. 10MCCh. 6 - Prob. 1DCh. 6 - Prob. 2DCh. 6 - Prob. 3DCh. 6 - Prob. 4DCh. 6 - Prob. 5DCh. 6 - Prob. 1PECh. 6 - Prob. 2PECh. 6 - Prob. 3PECh. 6 - Prob. 4PECh. 6 - Prob. 5PECh. 6 - Prob. 6PECh. 6 - Prob. 7PECh. 6 - Prob. 8PECh. 6 - Prob. 9PECh. 6 - Prob. 10PECh. 6 - Prob. 11PECh. 6 - Prob. 12PECh. 6 - Prob. 13PECh. 6 - Prob. 14PECh. 6 - Prob. 16PECh. 6 - Prob. 17PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- This is not a graded question so please don't disregard it as if it is.Thank you in advance professor! Note: This is a THEORETICAL QUESTION and no code should be used for solving it.arrow_forward: Write a function that adds two numbers. You should not use+ or any arithmeticoperators.arrow_forwardplease help in this codearrow_forward
- Prompt: When someone calls you on the phone, he or she looks up your number in a phone book (a function from names to phone numbers). When Caller ID shows who is calling, it has performed the inverse function, finding the name corresponding to the number. Explain why this situation represents an application of inverse of a function in familiar situations.arrow_forwardI just need the if statement to the code to execute.arrow_forwardCall a function to add 5+3. The function will show three variables but the calculation is done in main(). The result is 8arrow_forward
- True or falsearrow_forwardUse Python You are planning to add bookcases to a wall in your living room, but you don't know how many bookcases to buy. You decide to write a Python function, get_num_bookcases, to help. Your function needs to do the following: Take parameters for the width of the wall (an integer number of feet) and the width of a bookcase (an integer number of inches). (Your function does not read input from the keyboard; it gets its input through named parameters.) Calculate how many whole bookcases will fit on the wall using modular arithmetic (use div and/or mod, represented by the operators // and %, as needed to solve the problem). Return the number of bookcases. For example: Test Result print(get_num_bookcases(20, 50)) 4 print(get_num_bookcases(8, 15)) 6 print(get_num_bookcases(3, 40)) 0arrow_forwardTrue or falsearrow_forward
- An automated donation machine accepts donations via 10 or 20 bills to a maximum of $990. The machine needs to print a receipt with the donation amount in English, rather than numerically. Complete the following function which converts any number between 10 to 990 dollars to English.NOTE: You may define and use another function if necessary.NOTE: You should use arrays for this task. Use of switch statements or very long if/else if statements for printing is not allowed. However, using if/else if/else statements for the logic of your algorithm is permitted.NOTE: This function returns the result, and does not print it. Make sure the result is not lost when you return. Example function input and output (donation is 110):Input: 110Output: “one hundred ten dollars” string convertToEnglish (int donation); in C++ #include <iostream>#include <string>using namespace std; string convertToEnglish (int donation); int main() {int donation;cin>>donation;…arrow_forwardWrite a function that returns the greatest common divisor of 2 integers.arrow_forwardProblem 2: Write a function called digitMatch. The function has three integer parameters first , second and third that are positive and have the same number of digits. It returns the number of positions where their digits match. For example, if the function was applied to 17345, 97813 and 17313 it would return 1 because only the 2nd digits match. If parameters have illegal values your function can operate however you choose. For example, a program that uses the function follows. int main() { cout <« digitMatch(168, 567, 767) « endl; // prints 1 cout <« digitMatch(143, 243, 343) « endl; // prints 2 return 0; }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License