Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code should be in Python, all bits need to work in one problem together. They may seem like seperate parts but are not. Write function

Code should be in Python, all bits need to work in one problem together. They may seem like seperate parts but are not.

Write function reverseNum(n) that takes a positive integer, n, as input and returns the integer whose digits are the reverse of those in n. Assume that the input does not end in 0. For example reverseNum(12405) would return 50421. IMPORTANT RESTRICTION: you may not use any string operations. Yes, it would be easy using string operations but your job her is to do it with math operations. Attach a function printStringStats(inputString) that calculates and prints the number of occurrences of each vowel (consider the vowels to be only: a/A, e/E, i/I, o/O, and u/U) in the given string, and the total number of non-vowels and total number of uppercase letters in the string. NOTE: You must use a loop to count the vowel occurrences. You many not use the Python's built-in count function.

>>> printStringStats("My Octopus") 

should print:

'My Octopus' has 0 'a's, 0 'e's, 0 'i's, 2 'o's', 1 'u's, 7 non-vowels, and 2 upper case letters. 

Attach function, largestCharacter(inputString) that takes as input a string of one or more letters (and no other characters) and prints 1) the "largest" character in the string, where one character is larger than another if it occurs later in the alphabet (thus 'y' is larger than 'C' and both are larger than 'b') and 2) the index of the final occurrence of that character. When comparing letters in this problem, ignore case. I.e. 'e' and 'E' should be treated as equal. However, your output should use the case of the largest letter as it appears at the index of its final occurrence in the string. Thus, in the example below "The largest character is 'y' ..." would be incorrect. Important: your function must contain exactly one loop and you must determine the index of the character within the loop (i.e. you may not use Python's max, min, index, reverse, [::-1], or find, and you may not use any lists). You may, however, use Python's lower() function to help with string case if you wish.

For example, >>> largestCharacter("yRrcDefxBqubSlyjYelskd") 

should yield:

The largest character is 'Y' and occurs at position 16. Implement function printSequence(startNumber, stopNumber, factor, offset) that generates and prints a sequence of numbers as follows. The sequence starts with startNumber, and presume currNumber is the current number in the sequence. Then, until the currNumber is equal to stopNumber, apply the following rule to update currNumber: 

if currNumber is even, the next number is currNumber divided by 2. NOTE: use *integer division* here. You don't want any floating point values to appear.

if currNumber is odd, then next number is ((currNumber * factor) + offset)

Assume all inputs are positive integers and that startNumber is greater than or equal to stopNumber. printSequence should 1) print each number of the sequence on a separate line, and 2) print summary information about the sequence, include its length (i.e. the number of numbers generated in the sequence), and the maximum and minimum values encountered in the sequence. Your function should use a single while loop. For example:

>>> printSequence(5, 1, 3, 1) 5 16 8 4 2 1 Length of sequence: 6 max: 16 min: 1 >>> printSequence(18, 12, 3, 3) 18 9 30 15 48 24 12 Length of sequence: 7 max: 48 min: 9 

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions