Skip to content

Commit 04449c4

Browse files
Add files via upload
1 parent 74ca2e6 commit 04449c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3876
-0
lines changed

Ex39_Dictionary.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# create a mapping of state to abbreviation
2+
states = [
3+
'Oregon': 'OR',
4+
'Florida': 'FL',
5+
'California': 'CA',
6+
'New York': 'NY',
7+
'Michigan': 'MI'
8+
]
9+
10+
11+
# create a basic set of states and some cities in them
12+
cities = [
13+
'CA': 'San Francisco',
14+
'MI': 'Detroit',
15+
'FL': 'Jacksonville'
16+
]
17+
# add some more cities
18+
cities['NY'] = 'New York'
19+
cities['OR'] = 'Portland'
20+
21+
# print out some cities
22+
print '- ' * 10
23+
print "NY State has: ", cities['NY']
24+
print "OR State has: ", cities['OR']
25+
# print some states
26+
print '- ' * 10
27+
print "Michigan's abbreviation is: ", states['Michigan']
28+
print "Florida's abbreviation is: ", states['Florida']
29+
# do it by using the state then cities dict
30+
print '- ' * 10
31+
print "Michigan has: ", cities[states['Michigan']]
32+
print "Florida has: ", cities[states['Florida']]
33+
# print every state abbreviation
34+
print '- ' * 10
35+
for state, abbrev in states.items():
36+
print "%s is abbreviated %s" % (state, abbrev)
37+
# print every city in state
38+
print '- ' * 10
39+
for abbrev, city in cities.items():
40+
print "%s has the city %s" % (abbrev, city)
41+
# now do both at the same time
42+
print '- ' * 10
43+
for state, abbrev in states.items():
44+
print "%s state is abbreviated %s and has city %s" % (
45+
state, abbrev, cities[abbrev])
46+
print '- ' * 10
47+
# safely get an abbreviation by state that might not be there
48+
state = states.get('Texas', None)
49+
if not state:
50+
print "Sorry, no Texas."
51+
# get a city with a default value
52+
city = cities.get('TX', 'Does Not Exist')
53+
print "The city for the state 'TX' is: %s" % city

challenge3.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
n = int(raw_input())
2+
3+
if n%2 != 0:
4+
print "Weird"
5+
elif n%2 == 0:
6+
if (n>=2 and n<=5):
7+
print "Not Weird"
8+
elif (n>=6 and n<=20):
9+
print "Weird"
10+
elif (n>20):
11+
print "Not Weird"

challenge5.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a = int(raw_input())
2+
b = int(raw_input())
3+
print a/b
4+
print float(a)/b

doubts.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Write at least one more function of your own design, and run it 10 different ways. pg 88
2+
filename.seek(0)
3+
open
4+
flush
5+
non blocking mode
6+
decorator expression (pydoc def)
7+
lambda expressions
8+
doubt test.py
9+
ex39
10+
ex42 last 3 comment left
11+
12+
13+
////////////////////////////////////////////
14+
15+
CODE aNALYSIS DOUBT
16+
-------------------
17+
18+

ex1.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
print "hi "
2+
print "hello again"
3+
# print "I'm typing this" now this line a become a comment due to placing orthoscope '#'
4+
print "hello i m typing a line again"
5+

ex10_Escape.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
tabby_cat = "\tI'm tabbed in."
2+
persian_cat = "I'm split\non a line."
3+
backslash_cat = "I'm \\ a \\ cat."
4+
fat_cat = """
5+
I'll do a list:
6+
\t* Cat food
7+
\t* Fishies
8+
\t* Catnip\n\t* Grass
9+
"""
10+
print tabby_cat
11+
print persian_cat
12+
print backslash_cat
13+
print fat_cat
14+
15+
print '\n \t %r'%'\'\t "'
16+
print '\n %s'%'\' "'
17+
18+
19+
print "\n %r"%"' \""
20+
print "\n %s"%"' \""
21+

ex11_inputs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
print "how old are you?",
2+
age=raw_input()
3+
print "what is your weight?",
4+
weight=raw_input()
5+
print "how tall are you?",
6+
tall=raw_input()
7+
print "hey i want to ask some more question"
8+
print"do you know about stuxnet",
9+
10+
#Notice that we put a , (comma) at the end of each print line. This is so that
11+
#print doesn’t end the line with a new line character and go to the next line.

ex12_PromptedInputs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
age = raw_input("How old are you? ")
2+
height = raw_input("How tall are you? ")
3+
weight = raw_input("How much do you weigh? ")
4+
5+
print "So, you're %r old, %r tall and %r heavy." % (
6+
age, height, weight)
7+

ex13_arguments.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from sys import argv
2+
script, first, second, third = argv
3+
print "The script is called:", script
4+
print "Your first variable is:", first
5+
print "Your second variable is:", second
6+
print "Your third variable is:", third
7+

ex14_PromptAndPassing.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
from sys import argv
3+
script, user_name = argv
4+
prompt = '> '
5+
print "Hi %s, I'm the %s script." % (user_name, script)
6+
print "I'd like to ask you a few questions."
7+
print "Do you like me %s?" % user_name
8+
likes = raw_input(prompt)
9+
print "Where do you live %s?" % user_name
10+
lives = raw_input(prompt)
11+
print "What kind of computer do you have?"
12+
computer = raw_input(prompt)
13+
print """
14+
Alright, so you said %r about liking me.
15+
You live in %r. Not sure where that is.
16+
And you have a %r computer. Nice.
17+
""" % (likes, lives, computer)

0 commit comments

Comments
 (0)