-
-
Save LizaPiya/0e1d93217cacceb1e1876b0b1c89a761 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Write two functions, one called addit and one called mult. addit takes one number as an input and adds 5. mult takes one number as an input, and multiplies that input by whatever is returned by addit, and then returns the result. | |
| def addit(a): | |
| add = a+5 | |
| return add | |
| def mult(a): | |
| return a*addit(a) | |
| addit(5) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def changeit(lst): | |
| lst[0] = "Michigan" | |
| lst[1] = "Wolverines" | |
| return lst | |
| mylst = ['106', 'students', 'are', 'awesome'] | |
| newlst = changeit(list(mylst)) | |
| print(mylst) | |
| print(newlst) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Write a function called int_return that takes an integer as input and returns the same integer. | |
| def int_return(a): | |
| return a | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Write a function called add that takes any number as its input and returns that sum with 2 added. | |
| def add(a): | |
| return a+2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Write a function called change that takes any string, adds “Nice to meet you!” to the end of the argument given, and returns that new string. | |
| def change(string): | |
| return string + "Nice to meet you!" | |
| change("Piya") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Write a function, accum, that takes a list of integers as input and returns the sum of those integers. | |
| def accum(list): | |
| total=0 | |
| for i in list: | |
| total=total+i | |
| return total | |
| integer_list=[1,2,3] | |
| accum(integer_list) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Write a function, length, that takes in a list as the input. If the length of the list is greater than or equal to 5, return “Longer than 5”. If the length is less than 5, return “Less than 5”. | |
| def length(list): | |
| if len(list)>=5: | |
| return "Longer than 5" | |
| return "Less than 5" | |
| integer_list=[1,2,3,4,5,6] | |
| length(integer_list) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## You will need to write two functions for this problem. The first function, divide that takes in any number and returns that same number divided by 2. The second function called sum should take any number, divide it by 2, and add 6. It should return this new number. You should call the divide function within the sum function. Do not worry about decimals. | |
| def divide(a): | |
| return a//2 | |
| def sum(a): | |
| y=divide(a)+6 | |
| return y | |
| sum(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't the code of the first problem be mult(5).
Only when we call the mult function the addit function will get invoked as per your code, not the other way round.
def addit(num):
sum=num+5
return sum
def mult(num):
result=num*addit(num)
return result
print(mult(5))