Question: Python 3 please solve as much as possible Exercise 4. Hailstone Sequence Write a function hailstone(n) that takes an integer parameter n (assume it is

 Python 3 please solve as much as possible Exercise 4. Hailstone

Python 3 please solve as much as possible

Exercise 4. Hailstone Sequence Write a function hailstone(n) that takes an integer parameter n (assume it is always > 0), and that displays the hailstone sequence starting at n and ending with 1. In a hailstone sequence, each value x is followed either by: 3x + 1 if x is odd x/2 if x is even For example: hailstone(3) will produce the sequence: 3, 10, 5, 16, 8, 4, 2, 1 Exercise 5. Vowels. Write a function is_vowel(c) that returns True or False depending on whether its argument is a vowel or a consonant. You can use either a boolean expression or an if statement to do this. Write a function count_vowels(string) that takes a string argument and returns the number of vowels in the string. Write a program vowels.py that takes a string on the command line and prints the number of vowels in it. Exercise 6. Dice Game Write a console program that prompts the user for a desired sum, then repeatedly rolls two six- sided dice until the sum of the two dice values is the desired sum. The values of the two dice should be random values. Note that the function: random.randint(x, y) can be used to generate random integers in the range (x, y). Example: Desired sum: 9 5 and 1 = 6 6 and 2 = 8 5 and 6 = 11 8 and 1 = 9 Exercise 7. 3-Armstrong Numbers Write a function named is_three_armstrong that accepts an integer n as a parameter and returns True or False. A 3-Armstrong number is a number containing exactly 3 digits where the sum of each digit raised to the 3rd power equals the number itself. For example, 153 is a 3-Armstrong number because 13 +53 +33 = 153. Write a program that prints all the 3-Armstrong numbers. Exercise 8. Triangles Write a function is_valid(s1, s2, 53) that takes three floating point numbers as arguments and returns a boolean indicating whether or not these numbers can be the lengths of the sides of a valid triangle. The input is valid if the sum of any two sides is greater than the third side. Write a function area(s1, s2, 53) that returns the area of a triangle given the lengths of its three sides. The area of a triangle whose sides are s1, s2, and s3 is sqrt(s(s - 51)(s - s2)(s - 53)) where s = (51 +52 +53)/2. Write a program triangle.py that takes three floating point numbers as command line arguments and checks whether these numbers can be the lengths of the sides of a valid triangle. If the input is valid the program should also compute and print the area of the triangle. > python triangle.py 3.7 4.2 2.5 Valid triangle. Area is 4.589117562233507 > python triangle.py 2.7 5.2 1.3 Invalid triangle. Exercise 9. Substrings. Write a function substring(s1, s2, k) that takes two strings and an integer index k, and returns True if the first string appears as a substring in the second starting at location k, and False otherwise. You may assume that all strings consist of lowercase characters only. Write a function how_many() that takes two strings and returns the number of times the first string occurs in the second. Again, you may assume that all strings consist of lowercase characters only. For example, the call how many("bob", "azcbobobegghakl") should return 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!