0% found this document useful (0 votes)
6 views2 pages

CSC307 Python Concepts

The document presents Python programming concepts through various examples, including adding numbers, checking if a number is positive, negative, or zero, printing a range of numbers, creating a greeting function, and implementing a top-down design for adding two numbers. Each example includes code snippets and sample outputs demonstrating the functionality. The document serves as a practical guide for understanding basic programming constructs in Python.

Uploaded by

ammarrugged
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

CSC307 Python Concepts

The document presents Python programming concepts through various examples, including adding numbers, checking if a number is positive, negative, or zero, printing a range of numbers, creating a greeting function, and implementing a top-down design for adding two numbers. Each example includes code snippets and sample outputs demonstrating the functionality. The document serves as a practical guide for understanding basic programming constructs in Python.

Uploaded by

ammarrugged
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSC 307 – Python Programming Concepts

Name: Lukman Sidi Ahmad


Admission No: 18134015

1. Sequence – Add 4 Numbers


a = 1
b = 2
c = 3
d = 4
total = a + b + c + d
print("Sum =", total)

OUTPUT:
Sum = 10

2. Selection – Check Positive, Negative, or Zero


number = int(input("Enter a number: "))

if number > 0:
print("Positive number")
elif number < 0:
print("Negative number")
else:
print("Zero")

OUTPUT:
Enter a number: -2
Negative number

3. Iteration – Print Numbers 1 to 5


for i in range(1, 6):
print(i)

OUTPUT:
1
2
3
4
5

4. Modularity – Simple Greeting Function


def greet():
print("Hello!")
print("Welcome to Python")

greet()

OUTPUT:
Hello!
Welcome to Python

5. Top-Down Design – Add Two Numbers Using Functions


def get_numbers():
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
return a, b

def add_numbers(x, y):


return x + y

num1, num2 = get_numbers()


print("Sum =", add_numbers(num1, num2))

OUTPUT:
Enter first number: 4
Enter second number: 5
Sum = 9

You might also like