Wednesday, July 17, 2024

Boolean Flag

 A Boolean flag is a single Boolean variable used to indicate whether a specific condition has been met, often controlling the flow of loops and conditional statements in a program.

Example

valid_entries = False
while not valid_entries:
    try:
        num1 = float(input("Enter the first number: "))
        num2 = float(input("Enter the second number: "))
        valid_entries = True  # Set flag to True if inputs are valid
    except ValueError:
        print("Invalid input. Please enter numeric values.")
sum_result = num1 + num2
print(f"The sum of {num1} and {num2} is {sum_result}.")


Explanation

  • Boolean Flag: valid_entries is used to control the while loop.
  • While Loop: Continues to prompt for input until valid numeric values are entered.
  • Try-Except Block: Catches invalid inputs and prompts the user to re-enter.
  • Addition: Once valid entries are obtained, the sum is calculated and displayed.

Saturday, July 13, 2024

Temperature Conversion

Program to convert the given temperature from Fahrenheit to Celsius and vice versa depending upon user’s choice. 

print(" Temperature Conversion : ")

print(" 1. Celsius to Fahrenheit : ")

print(" 2. Fahrenheit  to celsius  : ")

option = int(input("enter your option : "))

if option == 1:

    celsius = float(input("Temperature in celsius : "))

    farenheit= 1.8 * celsius + 32

    print ("Temperature in Fahrenheit:", farenheit)

elif option == 2:

    farenheit= float(input("Temperature in Fahrenheit : "))

    celsius = ( farenheit- 32) / 1.8

    print ("Temperature in celsius : ", celsius)

else:

    print ("choose 1 or 2")

 

 

 

 

OUTPUT

 

Temperature Conversion : 

 1. Celsius to Fahrenheit : 

 2. Fahrenheit  to celsius  : 

enter your option : 1

Temperature in celsius : 23

Temperature in Fahrenheit: 73.4

 

Temperature Conversion : 

 1. Celsius to Fahrenheit : 

 2. Fahrenheit  to celsius  : 

enter your option : 2

Temperature in Fahrenheit : 23

Temperature in celsius :  -5.0

PYTHON PROGRAMMING LAB

 CONTENTS


Expressions

 An expression is a combination of symbols that, when evaluated, produces a value. Expressions are typically composed of a mix of operators, operands, and subexpressions.

  • An expression can also consist of a single literal or variable.Thus, 4, 3, and k are each expression. This expression has two subexpressions, 4 and (3 * k). Subexpression (3 * k) itself has two subexpressions, 3 and k. Any expression that is part of a larger expression is called a subexpression. 
  • Subexpressions can be denoted by the use of parentheses. Since a subexpression is an expression, any subexpression may contain subexpressions of its own

Arithmetic Expressions:

  • Expressions that evaluate to a numeric type are called arithmetic expressions.
  • If no parentheses are used, expressions are evaluated based on the rules of operator precedence.

output is 20

String Literals

 String literals, or “strings,” represent a sequence of characters. Strings are used for various purposes, including displaying screen output, storing text data, and processing textual information.

They can be delimited by either single (') or double (") quotes in Python. Strings must be contained all on one line, except when delimited by triple quotes.


Examples of string literals:

  • ‘Hello’
  • ‘Smith, John’
  • “Baltimore, Maryland 21210”

Strings can contain letters, digits, special characters, and blanks. An empty string is a string consisting of only a pair of matching quotes with nothing in between.

Strings may contain quote characters as long as different quotes are used to delimit the string. For example, “Jennifer Smith’s Friend”.

Python allows using more than one type of quote to handle situations where quotes are part of the string. Conventionally, single quotes are used for delimiting strings, and double quotes are used when needed.

Tuesday, July 9, 2024

What Is Computer Software?

What is Computer Software?

Computer software refers to a set of instructions, data, or programs used to operate computers and execute specific tasks.

There are two broad categories of software: system software and application software.

System Software:

·       This type of software is essential for the operation of a computer system such as memory management, file management, security, and hardware communication.

·       Examples of system software include operating systems (e.g., Windows, macOS, Linux), device driversfirmware, and utility programs

Application Software:

·       This type of software is designed to meet specific user needs and perform particular tasks.

·       Application software includes programs such as word processors, web browsers, spreadsheet applications, photo-editing programs, video games, and multimedia players.

Fundamental Hardware Components

All information within a computer system is represented using only two digits, 0 and 1, called binary representation. This binary representation is based on the use of electronic switches called transistors that can be either “on” or “off” (similar to a light switch). Computer hardware is built using integrated circuits (chips), which consist of millions or billions of transistors.

Computer hardware encompasses the physical components of a computer system. This includes essential elements like the central processing unit (CPU) and main memory, as well as peripheral components such as the keyboard, monitor, mouse, and printer.

1. Central Processing Unit (CPU):
  • The CPU acts as the “brain” of the computer system.
  • It contains digital logic circuitry to interpret and execute instructions.
  • The CPU is responsible for performing arithmetic and logical operations.

2. Main Memory:
  • Main memory stores currently executing programs that the CPU can quickly access.
  • It is volatile in nature, meaning the contents are lost when power is turned off.
  • Main memory provides fast read and write access for the CPU.

3. Secondary Memory:
  • Secondary memory is non-volatile storage used for long-term storage of programs and data.
  • Examples of secondary memory include magnetic storage (hard drive), optical storage (CD or DVD), and flash memory (USB drive).
  • Secondary memory retains data even when power is turned off.

4. Output Devices:
  • Output devices allow for input and output operations in the computer system.
  • Input devices include the mousekeyboard, and other devices for providing input.
  • Output devices include the monitorprinter, and other devices for displaying or producing output.

5. Buses
  • Buses transfer data between different components within the computer system.
  • Examples of buses include the data busaddress bus, and control bus.
  • Buses facilitate communication between the CPU, main memory, and input/output devices.






Sunday, July 7, 2024

PYTHON CONTENTS

UNIT I

UNIT II

UNIT III

UNIT IV

UNIT V

QUESTION BANK

    CONTENTS

    UNIT – I

    UNIT II

    UNIT III

    • Memory Management
    • Address Space
    • Dynamic Loading and Linking
    • Swapping
    • Contiguous Allocation
    • Segmentation
    • Paging
    • Structure of the Page Table.

    UNIT IV

    Virtual Memory Management: Demand Paging – Page Replacement Algorithms – Thrashing. File System:
    File Concept -. Access Methods – Directory and Disk Structure – Protection – File System Structures –
    Allocation Methods – Free Space Management.

    UNIT V

    QUESTION BANK

    UNIT I

    UNIT II

    UNIT III

    UNIT IV

    UNIT V