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

Programming Basics

The document covers basic programming concepts in Python, including variables, user input, conditional statements, and while loops. It provides examples for creating variables, obtaining user input, using if/else conditions, and implementing a while loop to repeat actions. These foundational elements are essential for writing simple programs in Python.
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)
2 views2 pages

Programming Basics

The document covers basic programming concepts in Python, including variables, user input, conditional statements, and while loops. It provides examples for creating variables, obtaining user input, using if/else conditions, and implementing a while loop to repeat actions. These foundational elements are essential for writing simple programs in Python.
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
You are on page 1/ 2

Programming Basics: Variables, Input, Conditions, While Loop

1. Variables

Variables are containers for storing data values.

In Python, you can create a variable just by assigning a value to it.

Example:

x=5

name = "Alice"

pi = 3.14

2. Input

To get input from the user, use the input() function.

It always returns a string, so you may need to convert it.

Example:

name = input("Enter your name: ")

age = int(input("Enter your age: "))

print("Hello", name, "! You are", age, "years old.")

3. Conditions (if/else)

Conditions allow you to run different code depending on whether something is True or False.

Example:

age = int(input("Enter your age: "))

if age >= 18:

print("You are an adult.")

else:

print("You are a minor.")

4. While Loop

A while loop repeats a block of code as long as a condition is True.


Programming Basics: Variables, Input, Conditions, While Loop

Example:

count = 1

while count <= 5:

print("Count is", count)

count += 1

This loop will print numbers from 1 to 5.

You might also like