-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some sample code snippets to learn python syntax
- Loading branch information
1 parent
cf446ce
commit 2ceb1d6
Showing
6 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from sys import argv | ||
script , filename =argv | ||
txt=open(filename) | ||
print "here is your file %r" %filename | ||
print txt.read() | ||
print "i'll also ask you to type it again" | ||
fi=raw_input("> ") | ||
tx=open(fi) | ||
print tx.read() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def multiply(a,b): | ||
c=a*b | ||
print "product is %r" %c | ||
def add(a,b): | ||
e=a+b | ||
print "addition is %r" %e | ||
multiply(3,4) | ||
add(3,4) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from sys import argv | ||
script, user_name = argv | ||
prompt = '> ' | ||
print "Hi %s, I'm the %s script." % (user_name, script) | ||
print "I'd like to ask you a few questions." | ||
print "Do you like me %s?" % user_name | ||
likes = raw_input(prompt) | ||
print "Where do you live %s?" % user_name | ||
lives = raw_input(prompt) | ||
print "What kind of computer do you have?" | ||
computer = raw_input(prompt) | ||
print """ | ||
Alright, so you said %r about liking me. | ||
You live in %r. Not sure where that is. | ||
And you have a %r computer. Nice. | ||
""" % (likes, lives, computer) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from sys import argv | ||
s,f,ss,t=argv | ||
print "the script is" , s | ||
print "var1 1 is" , f | ||
print "var 2 is" , ss | ||
print "var 3 is" , t |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
arr=[1,2,3] | ||
arrstr=["ashu" , "himu" , "piyu"] | ||
for num in arr: | ||
print "numbers are %d" %num | ||
for name in arrstr: | ||
print "names are %s" %name | ||
arrinput=[] | ||
for i in range(0,4): | ||
print "enter element number %d" %i | ||
number = raw_input("> ") | ||
arrinput.append(number) | ||
for inp in arrinput: | ||
print "elements are %r" %inp |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
print #"Hello World!" | ||
print "Hello Again" | ||
print "I like typing this." | ||
print "This is fun." | ||
print 'Yay! Printing.' | ||
print "I'd much rather you 'not'." | ||
print 'I "said" do not touch this.' | ||
print 3 + 2 < 5 - 7 | ||
cars = 100 | ||
space_in_a_car = 4.0 | ||
drivers = 30 | ||
passengers = 90 | ||
cars_not_driven = cars - drivers | ||
cars_driven = drivers | ||
carpool_capacity = cars_driven * space_in_a_car | ||
average_passengers_per_car = passengers / cars_driven | ||
print "We need to put about", average_passengers_per_car, "in each car." | ||
print "We have", passengers, "to carpool today." | ||
print "There will be", cars_not_driven, "empty cars today." | ||
print "We can transport", carpool_capacity, "people today." | ||
print "There are only", drivers, "drivers available." | ||
print "There are", cars, "cars available." |