Thursday, October 19, 2023

Python Programming - Lab- Core Lab 5 - Bsc CS DA -Bharathiar University - Program 3 - Write a python program that asks user to enter series of positive numbers (the user should enter a negative number to signal the end of series) and the program should display numbers in order and their sum

 

 B.Sc Computer Science with Data Analytics  

Python Programming - Lab

Core Lab 5  

Bharathiar University 

Program 3 - Write a python program that asks user to enter series of positive numbers   (the user should enter a negative number to signal the end of series) and the program should display numbers in order and their sum 

Source Code

# Initializing an empty list to store positive numbers
numbers = []

# Loop to take input from the user
while True:
num = int(input("Enter a positive number (or a negative number to end the series): "))
if num < 0:
break # Break the loop if a negative number is entered
numbers.append(num)

# Displaying the entered numbers
if len(numbers) > 0:
print("Entered numbers:", sorted(numbers))
# Calculating and displaying the sum of the entered numbers
print("Sum of the numbers:", sum(numbers))
else:
print("No positive numbers were entered.")

OUTPUT:
Enter a positive number (or a negative number to end the series): 5
Enter a positive number (or a negative number to end the series): 6
Enter a positive number (or a negative number to end the series): 3
Enter a positive number (or a negative number to end the series): 16
Enter a positive number (or a negative number to end the series): 10
Enter a positive number (or a negative number to end the series): -1
Entered numbers: [3, 5, 6, 10, 16]
Sum of the numbers: 40

Wednesday, October 18, 2023

Python Programming - Lab- Core Lab 5 - Bsc CS DA -Bharathiar University - Program 2 - Write a python program to find the largest three integers using if-else and conditional operator.

 

 B.Sc Computer Science with Data Analytics  

Python Programming - Lab

Core Lab 5  

Bharathiar University 

Program 2 - Write a python program to find the largest three integers using if-else and conditional operator.

Source Code

# Taking user input for three integers
a = int(input("Enter first integer: "))
b = int(input("Enter second integer: "))
c = int(input("Enter third integer: "))
# Find the largest among the three integers using if-else and conditional operators
largest = a if a > b and a > c else (b if b > c else c)


# Displaying the largest number
print("The largest number among", a, ",", b, "and", c, "is:", largest)


OUTPUT:
Enter first integer: 50
Enter second integer: 76
Enter third integer: 23
The largest number among 50 , 76 and 23 is: 76

Python Programming - Lab- Core Lab 5 - bharathiar University - Program 1 - Write a python program that displays the following information: Your name, Full address Mobile number, College name, Course subjects

 Python Programming - Lab

Core Lab 5  

Bharathiar University 

Program 1 - Write a python program that displays the following information: Your name, Full address Mobile  number, College name, Course subjects


Source Code

Here's a simple Python program that takes input for full name, address, mobile number, college name, and course subject, and then displays the entered information. 

Below is a Python program that prompts the user for their full name, address, mobile number, college name, and course subject. Then, it displays this information back to the user. Let's go through the code step by step. 

# Taking user input for personal information
full_name = input("Enter your full name: ")
address = input("Enter your address: ")
mobile_number = input("Enter your mobile number: ")
college_name = input("Enter your college name: ")
course_subject = input("Enter your course subject: ")


# Displaying the entered information
print("\nPersonal Information:")
print("Full Name:", full_name)
print("Address:", address)
print("Mobile Number:", mobile_number)
print("College Name:", college_name)
print("Course Subject:", course_subject)



Explanation of the steps:

User Input: The input() function is used to take input from the user.

The program prompts the user to enter their full name, address, mobile number, college name, and course subject.

The entered values are stored in respective variables (full_name, address, mobile_number, college_name, course_subject).

Display Information: The collected information is displayed back to the user using the print() function.

Each piece of information is printed along with its corresponding label.

When you run this program, it will ask you for the mentioned details one by one.

After you provide the input, it will display the entered information back to you.

Remember, you can run this Python code in any Python environment,

such as IDLE, Python shell, or a code editor like Visual Studio Code or PyCharm.


OUTPUT:
Enter your full name: Ram
Enter your address: 127, Ambedkar street, coimbatore
Enter your mobile number: 1234567890
Enter your college name: psg college of arts and science
Enter your course subject: python programming,data warehousing and data mining, deep learning

Personal Information:
Full Name: Ram
Address: 127, Ambedkar street, coimbatore
Mobile Number: 1234567890
College Name: psg college of arts and science
Course Subject: python programming, data warehousing and data mining, deep learning

Wednesday, October 11, 2023

BCA and B.Sc Programs - Programming in Java Lab - Bharathiar University -Program -9- Write a Java Program to create Menu Bars and pull down menus

 

Bharathiar University

Programming Java Lab
Java Program 9
Write a Java Program to create Menu Bars and pull down menus




Source Code

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;

public class UserMenu { 
private static String text=""; 
private static JTextArea content;
    public static void main(String[] args) {
        JFrame frame = new JFrame("Menu Program");
   frame.setSize(500, 500);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        content=new JTextArea(50,50);
        content.setFont(new Font("Serif",Font.PLAIN,20));
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        JMenuItem newItem = new JMenuItem("New");
        JMenuItem openItem = new JMenuItem("Open");
        JMenuItem saveItem = new JMenuItem("Save");
        JMenuItem exitItem = new JMenuItem("Exit");

        fileMenu.add(newItem);
        fileMenu.add(openItem);
        fileMenu.add(saveItem);
        fileMenu.addSeparator();
        fileMenu.add(exitItem);

      JMenu editMenu = new JMenu("Edit");
       JMenuItem cutItem = new JMenuItem("Cut");
      JMenuItem copyItem = new JMenuItem("Copy");
      JMenuItem pasteItem = new JMenuItem("Paste");
      JMenuItem selectallItem = new JMenuItem("Select All");

        editMenu.add(cutItem);
        editMenu.add(copyItem);
        editMenu.add(pasteItem);
        editMenu.add(selectallItem);

        JMenu helpMenu = new JMenu("Help");
        JMenuItem aboutItem = new JMenuItem("About");
        helpMenu.add(aboutItem);

        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(helpMenu);

frame.setJMenuBar(menuBar);
frame.add(new JScrollPane(content));
frame.setVisible(true);

newItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        content.setText("");
            }
        });

exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });



 cutItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
  text=(String)content.getSelectedText();
     content.replaceSelection("");

            }
        });

 copyItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
          text=(String)content.getSelectedText();

            }
        });

 pasteItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        int pos=content.getCaretPosition();
        content.insert(text,pos);
            }
        });

 selectallItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        content.selectAll();
            }
        });
        aboutItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(frame, "Menu Bar and Pull DownMenu Program");
            }
        });
    }
}

OUTPUT:






















Program 12 BCA Madras University BCA Object Oriented Programming using C++ Practical Madras University Program 12 Implement a telephone directory using files

  BCA Object Oriented Programming using C++ Practical Madras University  Program 12  Implement a telephone directory using files SOURCE CODE...