Slip Solutions Ty Java Python
Slip Solutions Ty Java Python
Slip1
Java que1:
Slip1 Q.1. Core Java: A) Write a ‘java’ program to display characters
from ‘A’ to ‘Z’
import java.io.*; class slip1 {
public static void main(String[] args) { char ch;
for(ch = 'A'; ch <= 'Z';ch++)
}
Output:
C:\Program Files\Java\jdk1.8.0_144\bin>javac slip1.java
C:\Program Files
Slip 1 .B)Write a ‘java’ program to copy only non-numeric data from one file to
another file
import java.io.*;
import java.util.*;
class Copyfile {
public static void main(String arg[]) throws Exception {
Scanner sc = new Scanner(System.in);
System.out.print("source file name :");
String sfile = sc.next();
System.out.print("destination file name:");
String dfile = sc.next();
FileReader fin = new FileReader(sfile);
FileWriter fout = new FileWriter(dfile, true);
int c;
while ((c = fin.read()) != -1) {
fout.write(c);
}
System.out.print("copy finish...");
fin.close();
fout.close();
}
}
Slip2
Que1: Write a java program to display all the vowels from a given string.
import java.io.*;
class Vowel {
public static void main(String args[]) {
String str = new String("HI Sakshi!");
for(int i=0; i<str.length(); i++) {
if(str.charAt(i) == 'a'|| str.charAt(i) == 'e'||
str.charAt(i) == 'i' || str.charAt(i) == 'o' ||
str.charAt(i) == 'u'||str.charAt(i) == 'A'|| str.charAt(i) == 'E'||
str.charAt(i) == 'I' || str.charAt(i) == 'O' ||
str.charAt(i) == 'U')
System.out.println("Given string contains " +
str.charAt(i)+" at the index " + i);
}
}
}
import java.awt.*;
import java.awt.event.*;
class Slip4 extends Frame
{
TextField statusBar;
Slip4()
{
addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
statusBar.setText("Clicked at (" +e.getX() + "," + e.getY() + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
statusBar.setText("Entered at (" + e.getX() + "," +e.getY() + ")");
repaint();
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
setLayout(new FlowLayout());
setSize(275,300);
setTitle("Mouse Click Position");
statusBar = new TextField(20);
add(statusBar);
setVisible(true);
}
public static void main(String []args)
{
new Slip4();
}
}
Slip3
Que1: write a ‘java’ program to check whether given number is Armstrong or
not.(Use static keyword)
import java.util.Scanner;
public class ArmstsrongNumber
{
static int num, temp, res=0, rem;
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter the Number: ");
num = scan.nextInt();
temp = num;
while(temp!=0)
{
rem = temp%10;
res = res + (rem*rem*rem);
temp = temp/10;
}
if(num==res)
System.out.println("\nArmstrong Number.");
else
System.out.println("\nNot an Armstrong Number.");
}
}
import java.util.*;
abstract class Shape
{
abstract public void area();
abstract public void vol();
}
class Cone extends Shape
{
int r,s,h;
Cone(int r,int s,int h)
{
super();
this.r=r;
this.s=s;
this.h=h;
}
public void area()
{
System.out.println("Area of Cone = "+(3.14*r*s));
}
public void vol()
{
System.out.println("volume of Cone = "+(3.14*r*r*h)/3);
}
}
class Cylinder extends Shape
{
int r,h;
Cylinder(int r,int h)
{
this.r=r;
this.h=h;
}
public void area()
{System.out.println("Area of cylinder= "+(2*3.14*r*h));
}
public void vol()
{
System.out.println("volume of Cylinder = "+(3.14*r*r*h));
}
}
class Slip15
{
public static void main(String a[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter radius, side and height for cone");
int r =sc.nextInt();
int s1 =sc.nextInt();
int h =sc.nextInt();
Shape s;
s=new Cone(r,s1,h);
s.area();
s.vol();
System.out.println("Enter radius, height for cylinder");
r =sc.nextInt();
h =sc.nextInt();
s=new Cylinder(r,h);
s.area();
s.vol();
}
}
Slip5
Que1: Write a java program to display following pattern:
5
45
345
2345
12345
import java.io.*;
public class pattern {
public static void main(String[] args) {
int n=5; for (int i=n;i>0;i—)
{
for (int j=i;j<=n;j++)
{
System.out.print(j+" ");
}
System.out.println();
}
}
}
QUE:2 Write a java program to accept list of file names through command
line and delete the files having extension “.txt”. Display the details of
remaining files such as FileName and size.
import java.io.*;
class Slip12
{
public static void main(String args[]) throws Exception
{
for(int i=0;i<args.length;i++)
{
File file=new File(args[i]);
if(file.isFile())
{
String name = file.getName();
if(name.endsWith(".txt"))
{
file.delete();
System.out.println("file is deleted " + file);
}
else
{
System.out.println(name + " "+file.length()+" bytes");
}
}
else
{
System.out.println(args[i]+ "is not a file");
}
}
}
}
Slip6: que1
Write a java program to accept a number from the user, if number is zero
then throw
user defined Exception “Number is 0” otherwise calculate the sum of first
and last digit of a given number (Use static keyword).
import java.util.*;
class ZeroException extends Exception
{
ZeroException()
{
super("Number is 0");
}
}
class Slip19
{
static int n;
public static void main(String args[])
{
int i,rem,sum=0;
try
{
Scanner sr=new Scanner(System.in);
n=sr.nextInt();
if(n==0)
{
throw new ZeroException();
}
else
{
rem=n%10;
sum=sum+rem;
if(n>9)
{
while(n>0)
{
rem=n%10;
n=n/10;
}
sum=sum+rem;
}
System.out.println("Sum is: "+sum);
}
}
catch(ZeroException e)
{
system.out.println(e);
}
}
}
Que2
Write a java program to display transpose of a given matrix.- Java
import java.io.*;
public class Matrix{
public static void main(String args[]){
//creating a matrix
int original[][]={{10,30,40},{20,40,30},{30,40,50}};
//creating another matrix to store transpose of a matrix
int transpose[][]=new int[3][3]; //3 rows and 3 columns
//Code to transpose a matrix
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
transpose[i][j]=original[j][i];
}
}
System.out.println("Printing Matrix without transpose:");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(original[i][j]+" ");
}
System.out.println();//new line
}
System.out.println("Printing Matrix After Transpose:");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(transpose[i][j]+" ");
}
System.out.println();//new line
}
}
}
Slip8:
Que1 :Define an Interface Shape with abstract method area(). Write a java
program to
calculate an area of Circle and Sphere.(use final keyword)
interface shape
{
final static float pi=3.14f;
float area(float r);
}
class Circle implements shape
{
public float area(float r)
{
return(3.14f*r*r);
}
}
class sphere implements shape
{
public float area(float r)
{
return(2*3.14f*r*r);
}
}
class Main
{
public static void main(String args[])
{
Circle cir=new Circle();
sphere sp=new sphere();
shape s;
s=cir;
system.out.println("Area of circle:"+s.area(3));
s=sp;
system.out.println("Area of Sphere:"+s.area(5));
}
}
QUE:2
Write a java program to display the files having extension .txt from a given
directory.
import java.io.File;
public class ListTxtFiles {
public static void main(String[] args) {
String directoryPath = "";
File directory = new File(directoryPath);
if (directory.exists() && directory.isDirectory()) {
File[] files = directory.listFiles();
if (files != null) {
System.out.println("List of .txt files in the directory:");
for (File file : files) {
if (file.isFile() && file.getName().toLowerCase().endsWith(".txt")) {
System.out.println(file.getName());
}
}
} else {
System.out.println("No files found in the directory.");
}
}else{
System.out.println("The specified directory does not exist or is not a
directory.");
}
}
}
Slip11
Que:1Write a menu dri e a menu driven java program using command line ar
am using command line arguments f guments for the following:
1. Addition
2. Subtraction
3. Multiplication
4. Division.
import java.io.*;
public class CommandLineCalculator {
public static void main(String[] args) {
if (args.length != 3) {
System.out.println("CommandLine Argument");
return;
}
String operation = args[0];
double num1 = Double.parseDouble(args[1]);
double num2 = Double.parseDouble(args[2]);
double result=0;
switch (operation) {
case "1":
result = num1 + num2;
System.out.println("Addition Result: " + result);
break;
case "2":
result = num1 - num2;
System.out.println("Subtraction Result: " + result);
break;
case "3":
result = num1 * num2;
System.out.println("Multiplication Result: " + result);
break;
case "4":
if (num2 == 0) {
System.out.println("Error: Division by zero is not allowed.");
} else {
result = num1 / num2;
System.out.println("Division Result: " + result);
}
break;
default:
System.out.println("Invalid operation.Please choose 1 for Addition, 2 for
Subtraction, 3 for Multiplication, or 4 for Division.");
}
}
}
import java.applet.*;
import java.awt.*;
public class Lamp extends java.applet.Applet {
public void init() {
resize(300,300);
}
public void paint(Graphics g) {
// the platform
g.fillRect(0,250,290,290);
// the base of the lamp
g.drawLine(125,250,125,160);
g.drawLine(175,250,175,160);
// the lamp shade; two arcs
g.drawLine(215,177,181,89);
// pattern on the shade
g.fillArc(78,120,40,40,63,-174);
g.fillOval(120,96,40,40);
g.fillArc(173,100,40,40,110,180);
}
}
SLIP13:
QUE:1write a java program to accept ‘n’ integers from the user & store thm
in an array list collection Display the elements of arraylist collection in
reverse order.
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class ReverseArrayList {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Integer> numberList = new ArrayList<Integer>();
System.out.print("Enter the number of integers (n): ");
int n = scanner.nextInt();
System.out.println("Enter " + n + " integers:");
for(int i=0;i<n;i++){
int num=scanner.nextInt();
numberList.add(num);
}
System.out.println("Elements in reverse order:");
for (int i = numberList.size() - 1; i >= 0; i--) {
System.out.println(numberList.get(i));
}
scanner.close();
}
}
QUE2: write a java program that ask user , name and then greet the user by
name before out putting the user name convert it to uppercase letter.
import java.util.Scanner;
import java.io.*;
public class GreetUser {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String userName = scanner.nextLine();
// Convert the user's name to uppercase
String upperCaseName = userName.toUpperCase();
System.out.println("Hello, " + upperCaseName + ", nice to meet you!");
scanner.close();
}
}
Slip 15: Slip 15 A) Write a java program to search given name into the array, if
it is found then display its index otherwise display appropriate message.
QUE1:
import java.applet.Applet;
import java.awt.*;
public class Slip30 extends Applet
{
public void paint(Graphics g)
{
g.drawOval(50,15,200,200);
g.fillOval(80,90,30,15);
g.fillOval(190,90,30,15);
g.drawOval(17,90,30,50);
g.drawOval(250,90,30,50);
g.drawLine(150,110,150,150);
//g.fillOval(80,160,10,35);
g.drawArc(100,160,100,30,170,200);
}
}
/*<applet code="Slip30.class" width="300" height="300"> </applet> */
Slip20
QUE1: A) Write a java program using AWT to create a Frame with title
“TYBBACA”, background color RED. If user clicks on close button then frame
should close.
import java.awt.*;
import ja import java.awt.event.WindowAdapter;
import ja import java.awt.event.WindowEvent;
public class RedFrame {
public static void main(String[] args) {
Frame frame = new Frame("TYBB ame("TYBBACA");
frame.setBackground(Color.RED);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}};
frame.setSize(400, 400);
frame.setVisible(true);
}
}
QUE2: SLIP 20.B) Construct a Linked List containing name: CPP, Java, Python
and PHP. Then extend your java program to do the following:
i. Display the contents of the List using an Iterator ii. Display the
contents of the List in reverse order using a ListIterator
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Iterator;
public class LinkedListDemo {
public static void main(String[] args) {
List<String> names = new LinkedList<>();
names.add("CPP");
names.add("JAVA");
names.add("PYTHON");
names.add("PHP");
System.out.println("Contents of the List using an It ents of the List using an
Iterator:");
Iterator<String>iterator =names.iterator();
while(iterator.hasNext()) {
System.out.println(iterator.next());
}
System.out.println("\nContents of the List in Reverse Order using a
ListIterator:");
ListIterator<String>listIterator = names.listIterator(names.size());
while(listIterator.hasPrevious()) {
System.out.println(listIterator.previous());
}
}
}
PYTHON SLIP SOLUTION
Slip 1
QUE1:A-WriteaPythonprogramtoacceptnnumbersinlistandremove
duplicatesfromalist.
First-Solution marks=[]
n=int(input('Enternumberofelements:'))
foriinrange(n): value=int(input())
marks.append(value)
print(marks) new_marks=[]
forxinmarks:
ifxnotinnew_marks:
new_marks.append(x)
print(new_marks)
Enternumberofelements:5
[1,2,3,5,2]
[1,2,3,5]
B)WritePythonGUIprogramtotakeacceptyourbirthdateandoutput
youragewhenabuttonispressed. #importallfunctionsfromthetkinter
fromtkinterimport*
fromtkinterimportmessagebox
dayField.delete(0,END)
monthField.delete(0,END)
yearField.delete(0,END)
givenDayField.delete(0,END)
givenMonthField.delete(0,END)
givenYearField.delete(0,END)
rsltDayField.delete(0,END)
rsltMonthField.delete(0,END)
rsltYearField.delete(0,END)
#functionforcheckingerror defcheckError():
#ifanyoftheentryfieldisempty
#thenshowanerrormessageandclear
#alltheentries
if(dayField.get()==""ormonthField.get()==""
oryearField.get()==""orgivenDayField.get()==""
orgivenMonthField.get()==""orgivenYearField.get()==""):
#showtheerrormessage
messagebox.showerror("InputError")
#clearAllfunctioncalling
clearAll()
return-1
#functiontocalculateAge defcalculateAge():
#checkforerror
value=checkError()
#iferrorisoccurthenreturn ifvalue== -1:
return
else:
#takeavaluefromtherespectiveentryboxes
#getmethodreturnscurrenttextasstring
birth_day=int(dayField.get())
birth_month=int(monthField.get())
birth_year=int(yearField.get())
given_day=int(givenDayField.get())
given_month=int(givenMonthField.get())
given_year=int(givenYearField.get())
#ifbirthdateisgreaterthengivenbirth_month
#thendonotcountthismonthandadd30tothedateso
#astosubtractthedateandgettheremainingdays
month=[31,28,31,30,31,30,31,31,30,31,30,31]
if(birth_day>given_day):
given_month=given_month-1
given_day=given_day+month[birth_month-1]
#ifbirthmonthexceedsgivenmonth,then
#donotcountthisyearandadd12tothe
#monthsothatwecansubtractandfindout
#thedifference
if(birth_month>given_month):
given_year=given_year-1
given_month=given_month+12
#calculateday,month,year
calculated_day=given_day-birth_day;
calculated_month=given_month-birth_month;
calculated_year=given_year-birth_year;
#calculatedday,month,yearwriteback #totherespectiveentryboxes
#insertmethodinsertingthe #valueinthetextentrybox.
rsltDayField.insert(10,str(calculated_day))
rsltMonthField.insert(10,str(calculated_month))
rsltYearField.insert(10,str(calculated_year))
#DriverCode if__name__=="__main__":
#CreateaGUIwindow
gui=Tk()
#SetthebackgroundcolourofGUIwindow
gui.configure(background="lightgreen")
#setthenameoftkinterGUIwindow
gui.title("AgeCalculator")
#SettheconfigurationofGUIwindow
gui.geometry("525x260")
#CreateaDateOfBirth:label
dob=Label(gui,text="DateOfBirth",bg="blue")
#CreateaGivenDate:label
givenDate=Label(gui,text="GivenDate",bg="blue")
#CreateaDay:label
day=Label(gui,text="Day",bg="lightgreen")
#CreateaMonth:label
month=Label(gui,text="Month",bg="lightgreen")
#CreateaYear:label
year=Label(gui,text="Year",bg="lightgreen")
#CreateaGivenDay:label
givenDay=Label(gui,text="GivenDay",bg="lightgreen")
#CreateaGivenMonth:label
givenMonth=Label(gui,text="GivenMonth",bg="lightgreen")
#CreateaGivenYear:label
givenYear=Label(gui,text="GivenYear",bg="lightgreen")
#CreateaYears:label
rsltYear=Label(gui,text="Years",bg="lightgreen")
#CreateaMonths:label
rsltMonth=Label(gui,text="Months",bg="lightgreen")
#CreateaDays:label
rsltDay=Label(gui,text="Days",bg="lightgreen")
#CreateaResultantAgeButtonandattachedtocalculateAge function
resultantAge=Button(gui,text="ResultantAge",fg="Black",bg=
"Red",command=calculateAge)
#CreateaClearAllButtonandattachedtoclearAllfunction
clearAllEntry=Button(gui,text="ClearAll",fg="Black",bg="Red",
command=clearAll)
#Createatextentryboxforfillingortypingtheinformation.
dayField=Entry(gui)
monthField=Entry(gui)
yearField=Entry(gui)
givenDayField=Entry(gui)
givenMonthField=Entry(gui)
givenYearField=Entry(gui)
rsltYearField=Entry(gui)
rsltMonthField=Entry(gui)
rsltDayField=Entry(gui)
#gridmethodisusedforplacing #thewidgetsatrespectivepositions
#intablelikestructure.
dob.grid(row=0,column=1)
day.grid(row=1,column=0)
dayField.grid(row=1,column=1)
month.grid(row=2,column=0)
monthField.grid(row=2,column=1)
year.grid(row=3,column=0)
yearField.grid(row=3,column=1)
givenDate.grid(row=0,column=4)
givenDay.grid(row=1,column=3)
givenDayField.grid(row=1,column=4)
givenMonth.grid(row=2,column=3)
givenMonthField.grid(row=2,column=4)
givenYear.grid(row=3,column=3)
givenYearField.grid(row=3,column=4)
resultantAge.grid(row=4,column=2)
rsltYear.grid(row=5,column=2)
rsltYearField.grid(row=6,column=2)
rsltMonth.grid(row=7,column=2)
rsltMonthField.grid(row=8,column=2)
rsltDay.grid(row=9,column=2)
rsltDayField.grid(row=10,column=2)
clearAllEntry.grid(row=12,column=2)
#StarttheGUI
gui.mainloop()
SLIP2:QUE1
A.WriteaPythonfunctionthatacceptsastringandcalculatethe
numberofuppercaselettersandlowercaseletters.
SampleString:'ThequickBrownFox'
ExpectedOutput:No.ofUppercasecharacters:3No.
ofLowercasecharacters:13 string=input('enterastring:')
up=low=ele=0 forxinstring:
ifx.isupper(): up+=1
elifx.islower():
low+=1
else:
ele+=1
print('No.ofUppercasecharacters:',up)
print('No.ofLowercasecharacters:',low)
print('otherspecialsymbols',ele)print(count1)
print("Thenumberofuppercasecharactersis:") print(count2)
enterastring:Abcdefg
No.ofUppercasecharacters:1
No.ofLowercasecharacters:6
otherspecialsymbols0
B)WritePythonGUIprogramtocreateadigitalclockwithTkinterto
displaythetime.
importtime fromtkinterimport*
canvas=Tk()
canvas.title("DigitalClock")
canvas.geometry("350x200") canvas.resizable(1,1)
label=Label(canvas,font=("Courier",30,'bold'),bg="blue",fg="white",bd
=30)
label.grid(row=0,column=1) defdigitalclock():
text_input=time.strftime("%H:%M:%S")
label.config(text=text_input)
label.after(200,digitalclock)
digitalclock() canvas.mainloop()
Output
Runningtheabovecodegivesusthefollowingresult−
SLIP3 :QUE1
A-WriteaPythonprogramtocheckifagivenkeyalreadyexistsina
dictionary.Ifkeyexistsreplacewithanotherkey/valuepair.
Dict={} n=int(input('enternumberofkeys:'))
forxinrange(0,n): key=input('enterthekey:')
ifkeyinDict: print('thegivenkeyexists!')
forkeyinDict.keys():
print(key,end='')
print('\n^usedifferntkeysfromabovelist')
key=input('enterthekey:')
value=input('enterthevalue:')
Dict[key]=value print(Dict)
enternumberofkeys:2
enterthekey:abc
enterthevalue:200
enterthekey:pqr
enterthevalue:300
{'abc':'200','pqr':'300'}
cl
assSt
udent
():
def__init__(self,roll_no,name,age,gender):
self.roll_no=roll_no
self.name=name self.age=age
self.gender=gender
classTest(Student): def
__init__(self,roll_no,name,age,gender,sub1mark,sub2mark,sub3mark,):
super().__init__(roll_no,name,age,gender)
self.mark1=sub1mark self.mark2=sub2mark
self.mark3=sub3mark
defget_marks(self):
self.total=self.mark1+self.mark2+self.mark3 print(self.name,"\
b'smarks:",self.total) print("sub1marks:",self.mark1)
print("sub2marks:",self.mark2) print("sub3marks:",self.mark3)
p1=Test(1,"amar",19,'male',82,89,76)
p2=Test(2,'priya',20,'female',94,91,84)
p1.get_marks() p2.get_marks()
abc'smarks:247
sub1marks:82
sub2marks:89
sub3marks:76
pqr'smarks:269
sub1marks:94
sub2marks:91
sub3marks:84
SLIP5: QUE1
Que 1: A)WriteaPythonscriptusingclass,whichhastwomethods
get_Stringandprint_String.get_Stringacceptastringfromthe
userandprint_Stringprintthestringinuppercase.
class Str1():
def __init__(self,demo=0):
self.demo=demo
def set_String(self,demo):
self.demo=demo
def print_streing(self):
str=self.demo
print(str.upper())
A=Str1()
A.set_String(rowinput)
A.print_streing()
a=0;b=1
print(b)
a,b=b,a+b
if n==0:
print('0')
else:
print(0)
generator(n)
slip 6
que 1) write a python program script using packages to calculate area and
volume of cube and sphere.
import math
volume=(4/3)*math.pi*pow(r,3)
av=6*pow(r,2)
vc=pow(r,3)
que 2) write python program GUI program to create a lable and change
the lable font style.(font name .bold,sixe) specify seprate check button for
each style.
win= Tk()
win.geometry("650x250")
def size_1():
text.config(font=('Arial',20))
def size_2():
text.config(font=('Helvetica bold',40))
text.pack()
frame= Frame(win)
#Create a label
button1.pack(pady=10)
button2.pack(pady=10)
frame.pack()
win.mainloop()
Slip 8
#create a tuple
tuplex = 2, 4, 5, 6, 2, 3, 4, 4, 7
print(tuplex)
count = tuplex.count(4)
print(count)
que 2)write a python class which has two methods get string from the user
ad print string print the string in upper case further modify the program to
reverse a string word by word and print it in lower case.
class Str1():
def __init__(self,demo=0):
self.demo=demo
def set_String(self,demo):
demo=demo.upper()
self.demo=demo
def print_streing(self):
return self.demo
A=Str1()
A.set_String(str1)
Slip11
x = (1,2,3,4)
y = (3,5,2,1)
z = (2,2,3,1)
print("Original lists:")
print(x)
print(y)
print(z)
print(result)
que 2) write a python GUI program to add menu bar with name of colors
as option to change the background color as per selection from menu
option.
def redcolor():
root.configure(background = 'red')
def greencolor():
root.configure(background = 'green')
def yellowcolor():
root.configure(background = 'yellow')
def violetcolor():
root.configure(background = 'violet')
def bluecolor():
root.configure(background = 'blue')
def cyancolor():
root.configure(background = 'cyan')
root = Tk()
root.title('COLOR MENU')
menubar = Menu(root)
activeforeground='cyan')
color.add_command(label ='Green',command =
greencolor,activebackground='green',
activeforeground='blue')
color.add_command(label ='Blue',command =
bluecolor,activebackground='blue',
activeforeground='yellow')
color.add_command(label ='Yellow',command =
yellowcolor,activebackground='yellow',
activeforeground='blue')
color.add_command(label ='Cyan',command =
cyancolor,activebackground='cyan',
activeforeground='red')
color.add_command(label ='Violet',command =
violetcolor,activebackground='violet',
activeforeground='green')
color.add_separator()
root.config(menu = menubar)
mainloop()
Slip13
try:
except ValueError:
q=[]
q.append(10)
q.append(100)
q.append(1000)
q.append(10000)
print(q.pop(0))
print(q.pop(0))
print(q.pop(0))
Slip15
class StudentDetails:
def AcceptDetails(self):
def ModifyDetails(self):
self.oldmark=self.mark
print("Student Name:",self.name)
S=StudentDetails()
S.AcceptDetails()
S.ModifyDetails()
Que 2) write a python program to accept the string and remove the
characters which have odd index values of given string using user defined
function.
def removeodd(string):
str2=''
for x in range(len(string)):
if x%2==0:
str2=str2+string[x]
return str2
Que 1) write a python program to create a classs circle and computes the
area of circumference of a circle (use parameterized constructor.)..
class Circle():
def __init__(self,Radius):
self.Radius=Radius
def area(self):
a=pi*self.Radius*self.Radius
return round(a,2)
def circumference(self):
c=2*self.Radius*pi
return round(c,2)
a=Circle(r)
d =dict()
for x in range(1,n+1):
d[x]=x*x
print(d)
method 2:
print(d)