Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save LizaPiya/188ae25abfd61106b0dfef2b5a30637a to your computer and use it in GitHub Desktop.

Select an option

Save LizaPiya/188ae25abfd61106b0dfef2b5a30637a to your computer and use it in GitHub Desktop.
Functions
## Write a function named same that takes a string as input, and simply returns that string.
def same (string):
return string
## Write a function called same_thing that returns the parameter, unchanged.
def same_thing(a):
return a
## Write a function called subtract_three that takes an integer or any number as input, and returns that number minus three.
def subtract_three (a):
return a-3
## Write a function called change that takes one number as its input and returns that number, plus 7.
def change(a):
return a+7
## Write a function called s_change that takes one string as input and returns that string, concatenated with the string ” for fun.”.
def s_change(a):
return a + " for fun."
## Write a function called decision that takes a string as input, and then checks the number of characters. If it has over 17 characters, return “This is a long string”, if it is shorter or has 17 characters, return “This is a short string”.
def decision(s1):
if len(s1) > 17:
return ("This is a long string")
else:
return ("This is a short string")
## Write a function named intro that takes a string as input. Given the string “Becky” as input, the function should return: “Hello, my name is Becky and I love SI 106.”
def intro(str1):
return("Hello, my name is "+ str1+ " and I love SI 106.")
intro("Becky") #calling the function named intro
#and passing the parameter Becky
## Write a function named total that takes a list of integers as input, and returns the total value of all those integers added together.
def total(lst):
tot=0
for i in lst:
tot=tot+i
return (tot)
y=total([1,2,3,4,5,6,7])
## Write a function called count that takes a list of numbers as input and returns a count of the number of elements in the list.
def count(lst):
values=0
for i in lst:
values=values+1
return values
y=count([1,2,3,4,5,6,7])
@inasse255
Copy link

thank you so mush

@sahibakb14
Copy link

helpful!

@FredrickWaitara
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment