You are on page 1of 2

Jenny Johnson

Computer Science
3rd
King
2/14/17

Chapter 5 Algorithm Workbench


(Ill indent on python)

1. Write a function named times_ten. The function should accept an argument and display the
product of its argument multiplied times 10.
def main():
value=int(input(Enter Value:))
times_ten (value)
#times_ten accepts argument and displays value times 10.
def times_ten(number):
result=(number*10)
print(The number times 10 is:, result)
#call the main function.
main ()
2. Examine the following function header, and then write a statement that calls the function, passing
12 as an argument.
def show_value(quantity):
def show_value(quantity):
print str(quantity)
show_value(12)
main()
3. Look at the following function header:
def my_function(a, b, c):
Now look at the following call to my_function:
my_function(3, 2, 1)
When this call executes, what value will be assigned to a? What value will be assigned to b?
What value will be assigned to c?
a= 3
b=2
c=1
4. What will the following program display?
def main():
x=1
y = 3.4
print(x, y)
change_us(x, y)
print(x, y)
def change_us(a, b):
a=0
b=0
print(a, b)
main()
1 3.4
1 0
Jenny Johnson
Computer Science
3rd
King
2/14/17
2 3.4
5. Asf
6. Write a function named welcome() that asks the user to enter his or her name and displays it
followed by a welcome message.
def welcome ():
name = input(Enter your name)
print(Welcome, name)
7. Tf
8. What will the following code display?
xdef display(x,y):
return(x%2==0)
print(display(4,7))
print(display(7,4))
invalid syntax
9. Write a function named area that accepts the base and perpendicular of a right-angled triangle as
two arguments and returns the area of that triangle.
main(){
float base, perpendicular, area;
printf("Enter base of right angled triangle\n");
scanf("%f", &base);
printf("Enter perpendicular of right angled triangle\n");
scanf("%f", &perpendicular);
/* Area of right angled riangle =
(Base X Perpendicular)/2 */
area =(base * perpendicular)/2;
printf("Area of triangle : %0.4f\n", area);
getch();
return 0;
10. Write a function named get_first_name that asks the user to enter his or her first name, and
returns it.
def get_first_name ():
Name = input(Enter your name: )
Print(Name)
return

You might also like