Skip to content

Commit 7948e5a

Browse files
committed
section2 final
1 parent 5b2e309 commit 7948e5a

File tree

13 files changed

+60
-21
lines changed

13 files changed

+60
-21
lines changed

Section2/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Section2/lecture22/Program1.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Program to print greeting message
2+
23
def greet(name):
3-
print("Python greetings: Hello ",name)
4-
n = input("Enter your Name \n")
5-
greet(n)
4+
print("Python greetings: Hello ", name)
5+
6+
7+
str = input("Enter your Name \n")
8+
greet(str)

Section2/lecture22/Program2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Program to find sum and average of n numbers
2-
n = total = int(input("Enter the limit \n"))
3-
sum = 0
4-
while n>0:
5-
sum = sum + int(input("Enter number \n"))
2+
n = num = int(input("Enter the limit \n"))
3+
total = 0
4+
while n > 0:
5+
total = total + int(input("Enter number \n"))
66
n = n - 1
7-
print("Sum of Numbers : ", sum)
8-
print("Average of Numbers : ", sum/total)
7+
print("Sum of Numbers : ", total)
8+
print("Average of Numbers : ", total/num)
99

1010

1111

Section2/lecture22/Program3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Program to print factorial of a given number
2+
23
def factorial(n):
34
if n <= 0:
45
return 1
56
else:
67
return n*factorial(n-1)
8+
9+
710
num = int(input("Enter the Number \n"))
8-
print(" Factorial of ", num," is ", factorial(num))
11+
print("Factorial of ", num," is ", factorial(num))

Section2/lecture23/Program1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Program to show line comments in python
2-
var1 = 12 # declaring variable
2+
var1 = 12 # declaring variable
33
print(var1) # printing the variable
44
# var2 = 43 We can comment lines of code

Section2/lecture23/Program2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Program to show multi line comments
22
def print_message(msg):
33
print(msg)
4+
5+
46
# line1
57
# line2
68
# line3
7-
print_message("Hello Python") # line comment
9+
10+
print_message("Hello Python") # line comment
811
"""
912
multi line string literal
1013
line2

Section2/lecture23/Program3.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Program to show python doc string
2+
23
def multiply(a,b):
34
""" Function to multiply a and b"""
45
return a*b
5-
print(multiply(12,2))
6+
7+
8+
print(multiply(12, 2))

Section2/lecture24/Program2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Program to show variable naming formats
22

3-
EmployeeName = "David" # Pascal notation
4-
employeeName = "David" # camel case notation
5-
employee_name = "David" # snake case notation
3+
EmployeeName = "David" # Pascal notation
4+
employeeName = "David" # camel case notation
5+
employee_name = "David" # snake case notation
66

Section2/lecture24/Program3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Program to show valid and invalid variable names
22
# 1var = 12 invalid cannot start with number
3-
var__1 = "hello" # valid can have any no of underscore in names
4-
_var = 12 # valid can start with underscore
3+
var__1 = "hello" # valid can have any no of underscore in names
4+
_var = 12 # valid can start with underscore
55
# $var = 32 invalid cannot start with $
66

Section2/lecture24/Program4.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Program to show scopes of variable in Python
22
var1 = 10
3+
4+
35
def change_value():
46
var1 = 20
7+
8+
59
change_value()
610
print("value of var1 after method call is ",var1)

0 commit comments

Comments
 (0)