My First Learning of Python
In [9]:
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.')
In [10]:
#how to write a comment out
In [12]:
print ("I could have code like this.") # and the comment after is ignored
# print "This won't run."
print ("This will run.")
In [21]:
print ("Hens", 25 + 30 / 6)
print ("Roosters", 100 - 25 * 3 % 4)
print ("Now I will count the eggs:")
print (3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
print (3 + 2 < 5 - 7)
print ("What is 3 + 2?", 3 + 2)
print ("Is it greater?", 5 > -2)
In [23]:
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 ("There are", cars, "cars available.")
print ("There are only", drivers, "drivers available.")
print ("There will be", cars_not_driven, "empty cars today.")
print ("We can transport", carpool_capacity, "people today.")
print ("We have", passengers, "to carpool today.")
print ("We need to put about", average_passengers_per_car, "in each car.")
In [45]:
my_name = 'Soham Chowdhury'
my_age = 28 # not a lie
my_height = 173 # cms
my_weight = 84 # kgs
my_eyes = 'Brown'
my_teeth = 'White'
my_hair = 'Black'
print ("Let's talk about %s." % my_name)
print ("He's %d cms tall." % my_height)
print ("He's %d kgs heavy." % my_weight)
print ("He's got %s eyes and %s hair." % (my_eyes, my_hair))
print ("His teeth are usually %s depending on the tea." % my_teeth)
print ("If I add %d, %d, and %d I get %d." % (my_age, my_height, my_weight, my_age + my_height + my_weight))
In [54]:
x = "There are %d types of people." % 2
Introvert = "Introvert"
are_not = "are not"
y = "Those who are %s and those who %s." % (Introvert, are_not)
print (x)
print (y)
print ("I said: %r." % x)
print ("I also said: '%s'." % y)
solution = False
Fact_evaluation = "Isn't that a fact?! %r"
print (Fact_evaluation % solution)
w = "This is the left side of..."
e = "a brain with a right side."
print (w + e)
In [60]:
print ("Baba black sheep have you any wool")
print ("His hair was white as %s." % 'snow')
print ("." * 12) # what'd that do?
end1 = "V"
end2 = "a"
end3 = "d"
end4 = "a"
end5 = "P"
end6 = "a"
end7 = "v"
print (end1 + end2 + end3 + end4),
print (end5 + end6 + end7)
In [67]:
formatter = "%r, %r, %r, %r"
print (formatter % (1, 2, 3, 4))
print (formatter % ("one", "two", "three", "four"))
print (formatter % (True, False, False, True))
print (formatter % (formatter, formatter, formatter, formatter))
print (formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
))
In [72]:
days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"
print ("Here are the days: ", days)
print ("Here are the months: ", months)
print ("""
There's something going on here.
With the three double-quotes.
We'll be able to type as much as we like.
""")
In [75]:
smelly_cat = "\tI smelled in."
asian_cat = "I'm split\non a line."
backslash_cat = "I'm \\ a \\ cat."
Groceries = """
I'll do a list:
\t* Dog food
\t* Bread
\t* Soft Drinks\n\t* Shampoo
"""
print (smelly_cat)
print (asian_cat)
print (backslash_cat)
print (Groceries)
In [80]:
print ("How old are you?"),
age = input()
print ("How tall are you?"),
height = input()
print ("How much do you weigh?"),
weight = input()
print ("So, you're %r old, %r tall and %r heavy." % (age, height, weight))
In [82]:
age = input("How old are you? ")
height = input("How tall are you? ")
weight = input("How much do you weigh? ")
print ("So, you're %r old, %r tall and %r heavy." % (age, height, weight))
In [91]:
from sys import argv
script,a,b = argv
print ("The script is called:", script)
print ("Your first variable is:", a)
print ("Your second variable is:", b)
Comments
Post a Comment