Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2012-10-11 14:49:57
Size: 105
Editor: hassan
Comment:
Revision 4 as of 2012-10-11 15:56:39
Size: 768
Editor: hassan
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
1. Write a function that calculates the volume of a sphere using the formula ''4/3*pi*''r''^3^''. What is the volume of a sphere with radius of 5?
Line 2: Line 3:
1. Define a function in interactive mode that calculates the volume of a sphere using the formula 4/3 Hint 1: The module {{{math}}} has a field called {{{pi}}}.

Hint 2: The answer is ''not'' 392.70.

2. Write a function that takes a list as argument and returns a list of unique elements from the original list.

3. Create a dictionary {{{D}}} with keys {{{a}}}, {{{b}}}, and {{{c}}}. What happens if you try to index an nonexistant key {{{d}}} ({{{D[d]}}})? Whath appens if you try to assign a nonexting key d (e.g. {{{D[d] = 'spam'}}})?

4. Write a {{{for}}} loop that prints a dictionary's items in sorted (ascending) order.

Hint: Use dictionary {{{keys}}} and the list {{{sort}}} method.

5. Write

1. Write a function that calculates the volume of a sphere using the formula 4/3*pi*r3. What is the volume of a sphere with radius of 5?

Hint 1: The module math has a field called pi.

Hint 2: The answer is not 392.70.

2. Write a function that takes a list as argument and returns a list of unique elements from the original list.

3. Create a dictionary D with keys a, b, and c. What happens if you try to index an nonexistant key d (D[d])? Whath appens if you try to assign a nonexting key d (e.g. D[d] = 'spam')?

4. Write a for loop that prints a dictionary's items in sorted (ascending) order.

Hint: Use dictionary keys and the list sort method.

5. Write

None: Meetings/Delhi2012/Practicals/Practical_2/PyEx (last edited 2013-06-03 12:24:10 by mark)