Com Prog
Com Prog
Python’s two direct competitors Python 3 isn't just a better version of Python 2 - it is
1. Perl - a scripting language originally a completely different language, although it's very
authored by Larry Wall; similar to its predecessor. When you look at them
2. Ruby - a scripting language originally from a distance, they appear to be the same, but
authored by Yukihiro Matsumoto. when you look closely, though, you notice a lot of
differences.
The former is more traditional, more conservative
than Python, and resembles some of the good old Canonical- They are also considered to be
languages derived from the classic C programming reference Pythons, as any other implementation of
language. In contrast, the latter is more innovative the language should follow all standards
and more full of fresh ideas than Python. Python established by the PSF.
itself lies somewhere between these two creations.
Guido van Rossum used the "C" programming
The Internet is full of forums with infinite language to implement the very first version of his
discussions on the superiority of one of these three language and this decision is still in force. All
over the others, should you wish to learn more Pythons coming from the PSF are written in the "C"
about each of them. language. There are many reasons for this
approach and it has many consequences.
Where can we see Python in action?
We see it every day and almost everywhere. It's This is why the PSF implementation is often
used extensively to implement complex Internet referred to as CPython. This is the most influential
services like search engines, cloud storage and Python among all the Pythons in the world.
tools, social media and so on. Whenever you use
any of these services, you are actually very close to Cython- one of a possible number of solutions to
Python, although you wouldn't know it. the most painful of Python's trait - the lack of
efficiency. Large and complex mathematical
niches where Python is absent, or is rarely seen: calculations may be easily coded in Python (much
1. low-level programming (sometimes called easier than in "C" or any other traditional
"close to metal" programming): if you want language), but the resulting code's execution may
to implement an extremely effective driver be extremely time-consuming.
or graphical engine, you wouldn't use - This is what Cython is intended to do - to
Python; automatically translate the Python code
2. applications for mobile devices: although (clean and clear, but not too swift) into "C"
this territory is still waiting to be conquered code (complicated and talkative, but agile).
by Python, it will most likely happen
someday. Another version of Python is called Jython.
"J" is for "Java". Imagine a Python written in Java
Two main kinds of Python, called Python 2 and instead of C. This is useful, for example, if you
Python 3: develop large and complex systems written entirely
1. Python 2- older version of the original in Java and want to add some Python flexibility to
Python. Its development has since been them. The traditional CPython may be difficult to
intentionally stalled, although that doesn't integrate into such an environment, as C and Java
mean that there are no updates to it. On the live in completely different worlds and don't share
contrary, the updates are issued on a many common ideas. Jython can communicate with
regular basis, but they are not intended to existing Java infrastructure more effectively. This is
modify the language in any significant way. why some projects find it usable and needful.
String- delimited with quotes
PyPy - a Python within a Python. In other words, it
represents a Python environment written in print() function
Python-like language named RPython (Restricted What is the effect the print() function causes?
Python). It is actually a subset of Python. The - takes its arguments (it may accept more
source code of PyPy is not run in the interpretation than one argument and may also accept
manner, but is instead translated into the C less than one argument)
programming language and then executed - converts them into human-readable form if
separately. PyPy is rather a tool for people needed (as you may suspect, strings don't
developing Python than for the rest of the users. require this action, as the string is already
PyPy is compatible with the Python 3 language. readable)
- sends the resulting data to the output device
Editor- which will support you in writing the code (it (usually the console); in other words,
should have some special features, not available in anything you put into the print() function will
simple tools); this dedicated editor will give you appear on your screen.
more than the standard OS equipment; What arguments does print() expect?
Console- which you can launch your newly written - Any. We'll show you soon that print() is able
code and stop it forcibly when it gets out of control; to operate with virtually all types of data
Debugger- able to launch your code step by step offered by Python. Strings, numbers,
and allowing you to inspect it at each moment of characters, logical values, objects - any of
execution. these may be successfully passed to print().
#Replication
#string * number
#number * string
print("Axcel"*5) print("Lesson 4 - Comparison Conditional
print("+" + 10 * "-" + "+") Statement")
print(("|" + " " * 10 + "|\n") * 5, end="")
print("+" + 10 * "-" + "+") #Comparison Operators
print("This is a ", " rectangle", sep="-") #(==,!=,>,<,>=,<=)
num=5 #Assignment Operator
#Type Conversion print(num == 5) #Equality Operator
leg_a = float(input("Input first leg length: ")) print(num != 5) #Inequality Operator
leg_b = float(input("Input second leg length: ")) print(num > 4) #Greater than Operator
print("Hypotenuse length is " + str((leg_a**2 + print(num < 2) #Less than Operator
leg_b**2) ** .5)) print(num >= 4) #Greater than Equal Operator
print(num <= 7) #Less than Equal Operator
#Lab 1
# input a float value for variable a here #Conditional Statements
# input a float value for variable b here #if...else statement - checks if true or False
vara=float(input("Enter your first number: ")) #Syntax
varb=float(input("Enter your second number: ")) #if(condition):
# codes here - Execute when true
# output the result of addition here #else:
print("\nThe sum of", vara, "and", varb, "is", # codes here - Execute when False
str(vara+varb))
# output the result of subtraction here #if(weather_is_good):
print("\nThe difference of", vara, "and", varb, "is", # go_for_walk()
str(vara-varb)) #else:
# output the result of multiplication here # stay_at_home()
print("\nThe product of", vara, "and", varb, "is",
str(vara*varb)) #this code defines age category
# output the result of division here #age=int(input("Enter your age: ")) #reads user
print("\nThe quotient of", vara, "and", varb, "is", input
str(vara/varb))
#checks the user's age
print("\nThat's all, folks!") #13-19 below... teen
#20-59... adult
#Lab 2 #60-100... senior
x = float(input("Enter value for x: ")) #out of range
a = (x+(1/x)) #if (age >= 13) and (age <= 19): #checks teen
b = (x+(1/a)) category
c = (x+(1/b)) # print("teen...")
y = (1/c) #elif (age >= 20) and (age <= 59): #checks adult
category
print("y =", y) # print("adult...")
#elif (age >= 60) and (age <= 100): #checks senior
#Lab 3 category
hour = int(input("Starting time (hours): ")) # print("senior...")
mins = int(input("Starting time (minutes): ")) #else:
dura = int(input("Event duration (minutes): ")) # print("out of age...")
a = 200 # Store the current largest number here.
b = 33 #largest_number = -999999999
if b > a:
print("b is greater than a") # Input the first value.
elif a == b: #number = int(input("Enter a number or type -1 to
print("a and b are equal") stop: "))
else:
print("a is greater than b") # If the number is not equal to -1, continue.
while number != -1:
#this code defines grade category # Is number larger than largest_number?
grade=float(input("Enter your grade:")) if number > largest_number:
# Yes, update largest_number.
#Grading System largest_number = number
if (grade >= 98) and (grade <= 100): #checks # Input the next number.
Excellent category number = int(input("Enter a number or type -1 to
print("Excellent, grade point is 1.00") stop: "))
elif (grade >= 94) and (grade <= 97): #checks
Superior category # Print the largest number.
print("Superior, grade point is 1.25") #print("The largest number is:", largest_number)
elif (grade >= 90) and (grade <= 93): #checks Very
Good category #for loop
print("Very Good, grade point is 1.50") #browse large collections of data item by item
elif (grade >= 88) and (grade <= 89): #checks Good #syntax
category #for i in range():
print("Good, grade point is 1.75") # do something()
elif (grade >= 85) and (grade <= 87): #checks # pass
Meritorious category
print("Meritorius, grade point is 2.00") #range() function
elif (grade >= 83) and (grade <= 84): #checks Very #pass one, two, three arguments
Satisfactory category
print("Very Satisfactory, grade point is 2.25") #Example 1
elif (grade >= 80) and (grade <= 82): #checks for i in range(10): #i == 0; i+1
Satisfactory category print("The value i is currently,", i)
print("Satisfactory, grade point is 2.50")
elif (grade >= 78) and (grade <= 79): #checks Fairly for q in range(2, 8):
Satisfactory category print("The value of q is currently", q)
print("Fairly Satisfactory, grade point is 2.75")
elif (grade >= 75) and (grade <= 77): #checks for n in range(2, 8, 3):
Passing category #first argument is the initialization
print("Passing, grade point is 3.00") #second argument is the range
elif (grade <= 70): #checks Failure category #third argument is the value of the increment
print("Failure, grade point is 5.00") print("The value of n is currently", n)
else:
print("Incomplete") power = 1
for expo in range(16):
print("Landicho, Axcel M.") print("2 to the power of", expo, "is", power)
power *= 2