Write a function factorial(number)
that receives an integer as an argument and computes the factorial of the integer. The factorial of
an integer is the product of all the positive integers less than or equal to that integer. For example, the factorial of
5 (denoted by 5!) is 5*4*3*2*1 = 120. The function should verify the input is a positive integer and return None if it is not.
Write a function keep_vowels(text)
that takes a string as an argument and returns a new string that only keeps the vowels and spaces of
the input string and omits the consonants. You can assume that the argument only contains letters and spaces, you do not need to write code to check for that. For example, keep_vowels('hello there')
should return 'eo ee'.
Write a function capitalize_vowels(text)
that satisfies the following specifications:
None
if the argument is not a string.
text
, except that all vowels in text
are capitalized. For example, capitalize_vowels('hello there')
should return 'hEllO thErE'.
Write a function foo(S1)
that takes as argument a string S1 that contains only letters and spaces, and returns a string S2 that contains first the consonants of S1 (in the order in which they appear in S1), and then the vowels of S1 (again, in the order in which they appear in S1). For example: foo('Hello world') should return the string 'Hllwrldeoo'.
We define that a string S is a well-formed name of a person if it follows the conventions:
Write a function multiple_options(N, option)
that:
None
if N
is not an integer or option
is not an integer.
option
is equal to 1, the function returns the square of N.option
is equal to 2, the function returns N multiplied by ten.option
is equal to 3, the function returns N divided by three.Write a program that takes a string as an argument and returns a new string that only keeps the vowels and spaces of the input string and omits the consonants. You can assume that the argument only contains letters and spaces, you do not need to write code to check for that. For example, if you passed the function 'hello there', it would return 'eo ee'.
compute_differences(n1, n2, n3)
that:
n1, n2, n3
, that are expected to be numbers (integers or floats).
None
.
n1, n2, n3
are numbers, the function returns the largest value among these three values: n2 - n1, n3 - n2, and n3 - n1.
compute_differences(15, 2.5, 30)
should return 27.5
.
compute_differences(5, 10, 30)
should return 25
.
foo(num)
that:
num
.
num
is not an integer or float, it returns None
.
num
is a number, it returns 3*num + 1.
For example:
foo(10)
should return 31
.
foo(2.5)
should return 8.5
.
def function1(z): # line 1 values = [1, 2, 3] # line 2 return values[z] # line 3 # line 4 def function2(z, y): # line 5 if y < 0: # line 6 val = 0 # line 7 elif y == 10: # line 8 val = 1 # line 9 else: # line 10 val = 2 # line 11 x = function1(val) # line 12 return x*z # line 13 # line 14 x = 10 # line 15 y = 2 # line 16 print(function2(y, x)) # line 17
repeat_number(s)
that:
num
.
num
3 times.
None
.
For example:
None
, because the input argument is a string.
None
, because the input argument is a string.
.
None
, because the input argument is a float.
.
IMPORTANT: make sure that, when the input argument is an integer, the output is also an integer. In other words, make sure that, if the input argument is of type int
, the return value is also of type int
.
x = 5
?
def Func(x): total = 0 for i in range(1, x+1): total += i * (i-1) return totalYour answer should be understandable by someone who does not know programming.
def counter(num, limit): #line 1 num += 1 #line 2 for x in range(1, num): #line 3 print(x, end = ','), #line 4 print('\n') #line 5 if (num == limit): #line 6 return #line 7 else: #line 8 counter(num, limit) #line 9 #line 10 num = 1 #line 11 limit = 5 #line 12 counter(num, limit) #line 13
Fibonacci(N)
that takes as input an integer N
and prints the first N numbers of Fibonacci sequence.
For example, Fibonacci(15)
prints the following:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610