Computer Science Do Now due 2:50 Python real numbers, arithmetic operators, programming Classwork: COMMENTS Mr. Manzoor
Research:
https://www.tutorialspoint.com/python/python_basic_operators.htm
https://www.includehelp.com/python/write-functions-to-find-square-and-cube-of-a-given-number.aspx
DO NOW:
Q1 . ___________ is used to declare a real type variable:
int
long
float
char
# NOTES: See this code
mystring = None
myfloat = None
myint = None
# testing code
if mystring == "hello":
print("String: %s" % mystring)
if isinstance(myfloat, float) and myfloat == 10.0:
print("Float: %f" % myfloat)
if isinstance(myint, int) and myint == 20:
print("Integer: %d" % myint)
mystring = None
myfloat = None
myint = None
# testing code
if mystring == "hello":
print("String: %s" % mystring)
if isinstance(myfloat, float) and myfloat == 10.0:
print("Float: %f" % myfloat)
if isinstance(myint, int) and myint == 20:
print("Integer: %d" % myint)
Q2 . ________ is arithmetic operator:
=
==
%
and
Aritmetic Operator | Description | Example |
---|---|---|
+ Addition | Adds values on either side of the operator. | a + b = 30 |
- Subtraction | Subtracts right hand operand from left hand operand. | a – b = -10 |
* Multiplication | Multiplies values on either side of the operator | a * b = 200 |
/ Division | Divides left hand operand by right hand operand | b / a = 2 |
% Modulus | Divides left hand operand by right hand operand and returns remainder | b % a = 0 |
** Exponent | Performs exponential (power) calculation on operators | a**b =10 to the power 20 |
// | Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity) − | 9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0 |
Python Programming Question:
Q3. Write a program that takes a number and displays its square and cube.
Program:
Program:
# NOTES: python program to find square and cube # of a given number # User defind method to find square def square (num): return (num*num) # User defind method to find cube def cube (num) : return (num*num*num) # Main code # input a number number = int (raw_input("Enter an integer number: ")) # square and cube print "square of {0} is {1}".format(number, square(number)) print "Cube of {0} is {1}".format(number, cube (number))
Classwork:
Q. What are comments in Python language?
Notes: 2 types
1) Hashtag
# defining the post code
salestax20 = 1.20 # defining a sales tax of 20%
2) Multi-line
version needs to be enclosed in
special quotation marks ("""
) to work, and not hash characters.
"""
LinuxThingy version 1.6.5
Parameters:
-t (--text): show the text interface
-h (--help): display this help
"""
Comments
Post a Comment