Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question # 1 Using Python's string capabilities, loops, and built - in functions, write the code for a Python user - defined function that removes

Question #1
Using Python's string capabilities, loops, and built-in functions,
write the code for a Python user-defined function that removes all characters
from a string except digit characters.
The function returns the resultant string.
The function prototype MUST be: def digits_only(s)
See table below for examples of the original and resultant strings.
Original (s):
"how many seas are there? 7""7"
"In 1990 Guido Van Rossum invented Python!" "1990"
"no digits in this string"
"who is the #1 team in the nhl in 2024?""12024"
Question #2
Using Python's string capabilities, loops, lists, and built-in functions,
write the code for a Python user-defined function that displays
'n' rows of a Fibonacci sequence!
The function prototype MUST be: def draw_fibonacci(n)
A Fibonacci sequence begins with the values and 1 and each subsequent
term in the sequence is comprised of the sum of the 2 previous terms.
Each new value to display is separated from the previous value by a space and
then the expression "ratio: n.xxxxxx"(where n.) represents the the ratio
of the last term divided by the second last term.
NOTE: Be careful of division by zero on the first term!
For example, a 9 row Fibonacci sequence would be:
0 ratio: 0.000000
01 ratio: 0.000000
11 ratio 1.000000
01112 ratio: 2.000000
11123 ratio: 1.500000
0111235 ratio: 1.666667
0111212358 ratio: 1.600000
0111223581321 ratio: 1.615385

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

0071808183, 9780071808187

More Books

Students also viewed these Databases questions