Write a python program to generate the Fibonacci series using While Loop.
Write a python program to check whether a given number is palindrome or not.
Write a python program to print the Pascal Triangle
Write a python program to Reverse an Integer
S. SHANAWAZ BASHA 7
Write a Python program to convert Decimal to Binary, Octal and Hexadecimal.
dec_num = int(input('Enter a decimal number: '))
print("The decimal value of", dec_num, "is:")
print(bin(dec_num), "in binary.")
print(oct(dec_num), "in octal.")
print(hex(dec_num), "in hexadecimal.")
Output:
Enter a decimal number: 27
The decimal value of 27 is:
0b11011 in binary.
0o33 in octal.
0x1b in hexadecimal.
Python Functions
A function is a block of code which only runs when it is called. We can pass data, known as parameters,
into a function. A function can return data as a result.
Declaring a Function
In Python a function is defined using the def keyword.
Example
def my_function():
print("Hello World")
Calling a Function
To call a function, we can use the function name followed by parenthesis.
Example
def my_function():
print("Hello World")
my_function()
Function Arguments or Parameters
Information can be passed into functions as arguments. Arguments are specified after the function
name, inside the parentheses. We can add as many arguments as we want, the function arguments can
be separated with a comma.
S. SHANAWAZ BASHA 8
The following example has a function with one argument (funcname). When the function is called, we
pass along a first name, which is used inside the function to print the full name:
Example
def my_function(funcname):
print(fname + "Engineering")
my_function("Computer Science")
my_function("Electronics and Communication")
my_function("Civil")
Output:
Computer Science Engineering
Electronics and Communication Engineering
Civil Engineering
Write a Python Program to make a Simple Calculator with basic arithmetic / mathematical operations.
S. SHANAWAZ BASHA 9
Output
Write a Python Program to Display Fibonacci Sequence Using Recursion
Output
S. SHANAWAZ BASHA 10