Google Search

Monday, March 2, 2015

Write a program that converts from currency from USD to INR. Use tables to pack the label and entry widgets

Write a program that converts from currency from USD to INR. Use tables to pack the label and entry widgets.










import pygtk pygtk.require('2.0') import gtk

class Conversion:


def  on_convert_clicked(self,widget): usd = self.usd_entry.get_text()
usd = int(usd) inr = usd * 44.75
self.inr_entry.set_text(str(inr))

def  on_window_destroy(self, widget, data=None): gtk.main_quit()

def __init__(self):

self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.on_window_destroy) self.window.set_border_width(5)

table = gtk.Table(4, 2, homogeneous=False) self.window.add(table)

ef = gtk.EXPAND | gtk.FILL

self.usd_label = gtk.Label("Enter USD Amount: ") table.attach(self.usd_label, 0, 1, 0, 1, 0, 0, 5, 5) self.usd_entry = gtk.Entry(0) table.attach(self.usd_entry, 1, 2, 0, 1, ef, 0, 5, 5)

self.inr_label = gtk.Label("Indian Value Is (INR): ") table.attach(self.inr_label, 0, 1, 1, 2, 0, 0, 5, 5) self.inr_entry = gtk.Entry(0) table.attach(self.inr_entry, 1, 2, 1, 2, ef, 0, 5, 5)

self.convert_button = gtk.Button("Convert") self.convert_button.connect("clicked", self.on_convert_clicked) table.attach(self.convert_button, 0, 2, 3, 4, ef, 0, 5, 5)

self.window.show_all()

def  main(self): gtk.main()

if __name__ == "__main__": conversion = Conversion() conversion.main()

Write a Python Program Print "Hello World" is printed when the user click on the button.


"Hello World" is printed when the user click on the button.






#!/usr/bin/env python

import pygtk pygtk.require('2.0') import gtk

class HelloWorld:

def on_button_clicked(self, widget, data=None): print "Hello World"


def on_window_destroy(self, widget, data=None): gtk.main_quit()

def __init__(self):

self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("destroy", self.on_window_destroy) self.window.set_border_width(5)

self.button = gtk.Button("Hello World") self.button.connect("clicked", self.on_button_clicked) self.window.add(self.button)

self.window.show_all()

def main(self): gtk.main()

if __name__ == "__main__": hello = HelloWorld() hello.main()

Write a Python script that creates a button with the text "Hello World"

Write a Python script that creates a button with the text "Hello World".

Objective

1.  Get started with GTK+.

2.  Learn to create widgets and associate callbacks.

Required Reading

   Getting Started and Movin On sections of the PyGTK 2.0 Tutorial  [http://www.pygtk.org/  pygtk2tutorial/index.html]

   ComboBox Widget section of the PyGTK 2.0 Tutorial  [http://www.pygtk.org/pygtk2tutorial/  index.html

import pygtk pygtk.require('2.0') import gtk

class HelloWorld:

def __init__(self):

self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.set_border_width(5)

self.button = gtk.Button("Hello World!") self.window.add(self.button) self.window.show_all()

def main(self): gtk.main()


if __name__ == "__main__": hello = HelloWorld() hello.main()

Write a Python script to create a populate a customer account balance database.

Write a Python script to create a populate a customer account balance database. The database consists of records of 3 fields:

1.  Account ID

2.  Account Name

3.  Account Balance

Solution. Make sure you know the username, password and database on your MySQL server. Create the file conf.py with the following contents. Replace your server hostname, username, password and database name.

Listing 2.1. conf.py

server = "your-server-name-here" username = "your-username-here" password = "your-password-here" database = "your-databaes-here"

import MySQLdb as db import sys

import conf

conn = db.connect("shark", conf.username, conf.password, conf.database) cursor = conn.cursor()

cursor.execute("DROP TABLE IF EXISTS accounts")

# Create Tables

sql = """CREATE TABLE accounts (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50),

balance DECIMAL(10, 2))"""

cursor.execute(sql)

# Insert into Tables


sql = """INSERT INTO accounts (name, balance) VALUES ('Alice', 500.00), ('Bob', 50000.00), ('Charlie', 100.00)"""
cursor.execute(sql)

Write a Python Program to Convert celsius to farenheit using Python

Write a Phyton Program to Convert temperature specified in celsius to Farenheit, using Python’s interactive prompt.

>>>  celsius = 100

>>>  farenheit = (9 * celsius / 5) + 32

>>>  print farenheit


212

Search By Students

Phython Programs 
Phython Programs to convert temp to celsius



Python - How to Program learn the basic types and control flow statements.

Objective

Python and learn the basic types and control flow statements.

Required

   Section An Informal Introduction to Python of the Python Tutorial  [http://docs.python.org/tutorial/].

   Section More Control Flow Tools of the Python Tutorial  [http://docs.python.org/tutorial/].

Starting Python

Start Python in interactive mode by invoking python in the command line.

$ python

Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2

Type "help", "copyright", "credits" or "license" for more information.


>>> 

Find hidden files related operations at the shell prompt.

Perform the following hidden files related operations at the shell prompt.

1.  Create a hidden file called .a.

2.  Create a hidden directory called .config.

3.  List all the files in the current directory including hidden files.



$ touch .a

$ mkdir .config

$ ls -a


.              ..            .a            .config

How to Perform file related operations at the shell prompt

Perform the following file related operations at the shell prompt.

1.  Create file named linux_distros.txt Add the names of the linux distributions you know.

2.  Display the content of the file linux_distros.txt.

3.  Copy the file linux_distros.txt to a new file list_of_linux_distributions.txt.

4.  Rename the file list_of_linux_distributions.txt to linux.txt.

5.  Delete the file linux.txt.

$ cat > linux_distros.txt debian

fedora ubuntu slackware centos OpenSuSE ^D

$ cat linux_distros.txt debian

fedora ubuntu slackware centos OpenSuSE

$ cp linux_distros.txt list_of_linux_distributions.txt

$ mv list_of_linux_distributions.txt linux.txt


$ rm linux.txt

write a program to print the name of the entered natural no 1 to 10



ALGORITHM:

Step 1: Start

Step 2: Read the value

Step 3: Switch case and print the name of the number Step 4: Print the desired output
Step 5: Stop

PROGRAM: import java.io.*; class natno

{

public static void main(String args[])throws IOException

{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int a;
System.out.println("Enter the value"); a=Integer.parseInt(br.readLine()); switch(a)

{ case 1 : System.out.println("One"); break ;

case 2 : System.out.println("Two"); break ;
case 3 : System.out.println("Three"); break ;
case 4 : System.out.println("Four"); break ;
case 5 : System.out.println("Five"); break ;
case 6 : System.out.println("Six"); break ;
case 7 : System.out.println("Seven"); break ;
case 8: System.out.println("Eight"); break ;
case 9 : System.out.println("Nine"); break ;
case 10 : System.out.println("Ten"); break ;



13


default : System.out.println("Invalid choice"); break ;
}

}

}

OUTPUT:

D:\JAVA>javac natno.java D:\JAVA>java natno Enter the value

7 Seven
D:\JAVA>

write a Java program to perform arithmetic operations using switch statement

ALGORITHM:

Step 1: Start

Step 2: Read the numbers. Step 3: Print the choice menu
Step 4: Read the choice from the user.

Step 5: Perform the arithmetic operations using switch case. Step 6: Print the desired output
Step 7: Stop

PROGRAM: import java.io.*; class arith

{public static void main(String args[])throws IOException

{BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); float a,b,c;
System.out.println("Enter the values"); a=Float.parseFloat(br.readLine()); b=Float.parseFloat(br.readLine()); System.out.println("1.Add"); System.out.println("2.Sub"); System.out.println("3.Mul"); System.out.println("4.Div"); System.out.println("Enter your choice");int ch; ch = Integer.parseInt(br.readLine());c = 0; switch(ch)
{ case 1 : c=a+b; break ;
case 2 : c=a-b; break ;
case 3 : c=a*b; break ;
case 4 : c=a/b; break ;
default : System.out.println("Invalid choice"); break ;}
System.out.println("Result is " +c);

}

}




11


OUTPUT:

D:\JAVA>javac arith.java D:\JAVA>java arith Enter the values

10

10

1.Add

2.Sub

3.Mul

4.Div

Enter your choice 3

Result is 100.0 D:\JAVA>

Write a Java Program to find calculate sum, average and check if pass or fail

ALGORITHM:

Step 1: Start

Step 2: Read marks in five subjects Step 3: Sum=m1+m2+m3+m4+m5 Step 4: Avg = sum/5f

Step 5: Print the sum and average

Step 6: If (m1>40) and (m2>40) and(m3>40) and(m4>40) and(m5>40) then pass else fail Step 8: Stop

PROGRAM: import java.io.*; class mark

{

public static void main(String args[])throws IOException

{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int m1,m2,m3,m4,m5,tot;
float avg;

System.out.println("Enter the mark"); m1=Integer.parseInt(br.readLine()); m2=Integer.parseInt(br.readLine()); m3=Integer.parseInt(br.readLine()); m4=Integer.parseInt(br.readLine()); m5=Integer.parseInt(br.readLine()); tot=m1+m2+m3+m4+m5;avg=tot/5; System.out.println("Total="+tot); System.out.println("Average="+avg); if((m1>=40)&&(m2>=40)&&(m3>=40)&&(m4>+40)&&(m5>=40))




{

System.out.println("Result=Pass");

if (avg>=60){System.out.println("Class=First");} else if (avg>=50) {System.out.println("Class=Second");}

else {System.out.println("Class=Third");
}}

else {System.out.println("Result=Fail"); }



9


}

}

OUTPUT:

D:\JAVA>javac mark.java D:\JAVA>java mark Enter the mark

80

80

80

80

80

Total=400

Average=80.0

Result=Pass

Class=First


D:\JAVA>