Saturday, 14 September 2024

Practical - 57 - Write a Python program to take temperature in Fahrenheit as input and convert it to Celsius.

Practical - 57 - Write a Python program to take temperature in Fahrenheit as input and convert it to Celsius.


Ans:

F=float(input("Enter the temperature in Fahrenheit: "))

C=5*(F-32)/9

print("Temperature in Celsius=", C)

 

Output:

Enter the temperature in Fahrenheit: 98.6

Temperature in Celsius= 37.0


Practical - 56 - Write a Python Program which accepts three numbers from user and displays their sum and average.

Practical - 56 - Write a Python Program which accepts three numbers from user and displays their sum and average.


Ans:

a=int(input("Enter first number: "))

b=int(input("Enter second number: "))

c=int(input("Enter third number: "))

sum=a+b+c

avg=sum/3

print("Sum=",sum)

print("Average=",avg)

 

Output:

Enter first number: 8

Enter second number: 5

Enter third number: 11

Sum= 24

Average= 8.0


Practical - 55 - Write a program in Python which accepts two numbers and calculate their sum, difference, multiplication and division.

Practical - 55 - Write a program in Python which accepts two numbers and calculate their sum, difference, multiplication and division.


Ans:

a=int(input("Enter first number: "))

b=int(input("Enter second number: "))

print("Sum=",a+b)

print("Difference=",a-b)

print("Multiplication=",a*b)

print("Division=",a/b)

 

Output:

Enter first  number: 8

Enter second number: 5

Sum= 13

Difference= 3

Multiplication= 40

Division= 1.6


Practical - 54 - Write a program in Python that accepts side of a square and find the area of the square.

Practical - 54 - Write a program in Python that accepts side of a square and find the area of the square.


Ans:

side=float(input("Enter the side of square: "))

area=side*side

print("Area=",area)

 

Output:

Enter the side of square: 8

Area= 64.0


Practical - 53 - Write a program in Python that accepts radius of a circle and prints its area.

 Practical - 53 - Write a program in Python that accepts radius of a circle and prints its area.


Ans:

radius=float(input("Enter the radius of a circle: "))

pi=3.14

area=pi*radius**2

print("Area=",area)

 

Output:

Enter the radius of a circle: 10

Area= 314.0

Tuesday, 10 September 2024

Operator precedence and associativity Practice questions in python

 What will be the output of following statement?

1.     22 % 3

2.     47%6

3.     -47%6

4.     47%-6

5.     -47%6

6.     2+3-1*2*3*2

7.     3*1**3

8.     2+9*((3*12)-8)/10

9.     4//2*3+5/2+1

10.  43.55+2/2

11.  4.00/(2.0+2.0)

12.  (2-6+3**2*3)+7

13.  24//6%3

14.  24//4//2

15.  x>>2=2

16.  x<<2

17.  4^12

18.  not(3>4)

19.  not(1&1)

20.  13.25+4/2

21.  3+3.00

22.  3**3.0

23.  343%15

24.  14 + 14%15//4

25.  5*10+11/2

26.  8*2+4**2//5-3

27.  1+(2-3)*4**5//6

28.  5%3+4**2

29.  6+5/4**2//5+8

30.  16*5/4*2/5-8

31.  6/3 + 4**3//8-4

32.  4+3*5/3-5%2

33.  5+3**2/2

34.  3-2**2**3+99/11

35.  15.0/4+(8+3.0)

36.  10 * (3 + 5) // 2

37.  8 / 2 + 2 * 3

38.  5 + 2 * 3 ** 2

39.  8 % 3 + 2 ** 2 * (2 + 2)

40.  (3 + 2) * 4 / 2 ** 2

41.  7<4 or 6>3 and not 10 ==10 or 17>4

42.  5<10 and 12>7 or not 7>4

43.  not(True) and False

44.  True or False

45.  not(False and True)

46.  True and not(False)

47.  4 < 5 and 5 < 6

48.  3 != 3 or 5 > 4

49.  10 == 10 and 5 > 6

50.  (5 != 5) or (6 >= 6)

51.  (6 > 5) or (7 <= 7)

52.  10 > 5 < 2

53.  3 * "Hello"

Sunday, 1 September 2024

कहानी: "रोबोटिक आर्म का चमत्कार: पायथन प्रोग्रामिंग की शक्ति"

 11वीं कक्षा के छात्रों के बीच रोहित एक ऐसा छात्र था, जो भौतिकी, रसायन विज्ञान, और गणित में गहरी रुचि रखता था। उसका सपना एक दिन इंजीनियर बनकर कुछ नया आविष्कार करने का था। लेकिन कंप्यूटर विज्ञान, खासकर पायथन प्रोग्रामिंग, में उसकी रुचि न के बराबर थी। उसे लगता था कि पायथन और प्रोग्रामिंग सिर्फ सॉफ्टवेयर डेवलपर्स के लिए हैं, और उसका उससे कोई लेना-देना नहीं है।

एक दिन, उनके स्कूल में एक नेशनल लेवल साइंस फेयर का आयोजन हुआ, जहां छात्रों को अपने नवाचारों को प्रदर्शित करने का अवसर मिला। रोहित ने अपने भौतिकी और गणित के ज्ञान का उपयोग करते हुए एक रोबोटिक आर्म बनाने का निर्णय लिया, जो विभिन्न वस्तुओं को उठा सके और उन्हें एक स्थान से दूसरे स्थान पर रख सके। उसने बहुत मेहनत की और यांत्रिक भागों को जोड़ने में सफल रहा। लेकिन जब उसने देखा कि आर्म सही दिशा में काम नहीं कर रही है, तो वह परेशान हो गया।

रोहित के एक दोस्त, आर्यन, जो कंप्यूटर विज्ञान में गहरी रुचि रखता था, ने पायथन प्रोग्रामिंग की मदद से एक अद्भुत ड्रोन बनाया था, जिसे मोबाइल से नियंत्रित किया जा सकता था। आर्यन ने रोहित से कहा, "रोहित, तुम्हारा रोबोटिक आर्म वास्तव में शानदार है, लेकिन इसे सटीकता और नियंत्रण देने के लिए तुम्हें पायथन प्रोग्रामिंग की जरूरत है। पायथन की मदद से तुम अपने रोबोट को कोडिंग के जरिए निर्देश दे सकते हो, ताकि वह सही दिशा में काम करे।"

पहले तो रोहित ने सोचा कि प्रोग्रामिंग सीखना उसके लिए बहुत मुश्किल होगा, लेकिन आर्यन ने उसे समझाया कि पायथन एक सरल और शक्तिशाली भाषा है। रोहित ने आर्यन की मदद से पायथन के कुछ बेसिक कोड्स सीखे और अपने रोबोटिक आर्म के लिए एक प्रोग्राम लिखा। यह देखकर रोहित चकित रह गया कि उसके रोबोटिक आर्म ने बिल्कुल सही ढंग से काम करना शुरू कर दिया।

साइंस फेयर के दिन, रोहित का प्रोजेक्ट सभी की नजरों का केंद्र बन गया। जजों ने कहा, "रोहित, तुम्हारे रोबोटिक आर्म की डिजाइन और कार्यक्षमता अद्भुत है, लेकिन जिस चीज़ ने इसे सबसे ज्यादा प्रभावी बनाया, वह है पायथन प्रोग्रामिंग। प्रोग्रामिंग ने तुम्हारे विचार को वास्तविकता में बदल दिया है।"

रोहित ने महसूस किया कि पायथन प्रोग्रामिंग ने उसके रोबोटिक आर्म में जान फूंक दी थी। उसने समझा कि आज के दौर में पायथन जैसी प्रोग्रामिंग भाषाएँ न केवल सॉफ्टवेयर डेवलपर्स के लिए, बल्कि हर उस व्यक्ति के लिए महत्वपूर्ण हैं जो किसी भी क्षेत्र में कुछ नया और अद्वितीय करना चाहता है। चाहे वह इंजीनियरिंग हो, विज्ञान, या किसी भी अन्य क्षेत्र, प्रोग्रामिंग का ज्ञान आपके सपनों को पंख दे सकता है।

इस अनुभव ने रोहित की सोच बदल दी। उसने अब पायथन प्रोग्रामिंग को भी उतनी ही गंभीरता से लेना शुरू कर दिया जितना वह अपने अन्य विषयों को लेता था। आगे चलकर, रोहित एक सफल रोबोटिक्स इंजीनियर बना, और उसकी सफलता के पीछे पायथन प्रोग्रामिंग का महत्वपूर्ण योगदान था।

इस कहानी से यह संदेश मिलता है कि पायथन प्रोग्रामिंग केवल एक विषय नहीं है, बल्कि वह उपकरण है जो आपके नवाचारों को जीवन में बदल सकता है। इसलिए, यदि आप अपनी शिक्षा और करियर में ऊंचाई पर पहुंचना चाहते हैं, तो पायथन को दिल से सीखें। यह आपको उन क्षेत्रों में भी सफलता दिला सकता है, जिनके बारे में आपने कभी सोचा भी नहीं था।

कहानी: "सफलता की चाबी: कंप्यूटर विज्ञान की महत्ता"

 रोहित बहुत होशियार था और उसका सपना एक दिन इंजीनियर बनने का था। वह भौतिकी, रसायन विज्ञान, और गणित में बहुत मेहनत करता था, क्योंकि उसे लगता था कि ये विषय ही उसकी सफलता की कुंजी हैं। लेकिन कंप्यूटर विज्ञान में उसकी रुचि बहुत कम थी। वह अक्सर सोचता था कि कंप्यूटर विज्ञान से उसे कोई खास फायदा नहीं मिलेगा और वह इस विषय को हल्के में लेता था।

एक दिन, उनके स्कूल में एक साइंस फेयर का आयोजन हुआ। इस फेयर में देशभर के छात्रों को अपनी परियोजनाएं प्रदर्शित करने का मौका मिला। रोहित ने भी अपनी भौतिकी और गणित के ज्ञान का उपयोग करके एक प्रोजेक्ट तैयार किया। वह आत्मविश्वास से भरा था और उसे यकीन था कि उसका प्रोजेक्ट सबसे अच्छा होगा।

साइंस फेयर के दिन, उसने देखा कि उसके सहपाठियों ने कंप्यूटर विज्ञान का उपयोग करके अद्भुत प्रोजेक्ट्स बनाए थे। किसी ने एक ऐप बनाया था जो किसानों को फसल की जानकारी देता था, तो किसी ने एक रोबोट बनाया था जो घर के काम कर सकता था। रोहित का प्रोजेक्ट भी अच्छा था, लेकिन कंप्यूटर विज्ञान की कमी के कारण वह इन अद्वितीय प्रोजेक्ट्स के सामने फीका पड़ गया।

जजों ने जब सभी प्रोजेक्ट्स की समीक्षा की, तो उन्होंने कहा, "रोहित, तुम्हारा प्रोजेक्ट बहुत अच्छा है, लेकिन अगर इसमें कंप्यूटर विज्ञान की मदद होती, तो यह और भी उत्कृष्ट हो सकता था। आज के युग में कंप्यूटर विज्ञान वह चाबी है जो हर दरवाजा खोल सकती है। यदि तुम इसे नजरअंदाज करते हो, तो तुम अपने सपनों की उड़ान में खुद ही बाधा डाल रहे हो।"

रोहित को समझ में आ गया कि उसने कंप्यूटर विज्ञान को हल्के में लेकर बहुत बड़ी गलती की थी। वह जान गया कि आज के डिजिटल युग में कंप्यूटर विज्ञान के बिना किसी भी क्षेत्र में उत्कृष्टता प्राप्त करना बहुत मुश्किल है। उसने ठान लिया कि अब वह कंप्यूटर विज्ञान में भी उतनी ही मेहनत करेगा जितनी वह भौतिकी, रसायन विज्ञान, और गणित में करता है।

इस घटना के बाद, रोहित ने कंप्यूटर विज्ञान को गंभीरता से लेना शुरू किया। उसने अपने समय को सही तरीके से विभाजित किया और सभी विषयों में समान रूप से मेहनत की। कुछ वर्षों बाद, रोहित एक सफल सॉफ्टवेयर इंजीनियर बन गया और उसने अपनी मेहनत और समर्पण से एक ऐसा सॉफ्टवेयर बनाया जो लाखों लोगों की जिंदगी बदलने वाला था।

इस कहानी से हमें यह सीख मिलती है कि जीवन में हर विषय का अपना महत्व होता है। कंप्यूटर विज्ञान आज के युग में केवल एक विषय नहीं, बल्कि सफलता की चाबी है। इसलिए, अगर आप अपने सपनों को साकार करना चाहते हैं, तो हर विषय को समान महत्व दें और कंप्यूटर विज्ञान को दिल से पढ़ें। यही वह रास्ता है जो आपको आपके लक्ष्य की ओर ले जाएगा।

Saturday, 24 August 2024

Python Tutorial - 2 - Class 11 Computer Science - Flowchart

Flowchart

·        A flowchart is a graphical representation of an algorithm.

·        A flowchart contains various shapes which are connected by arrows, which showing the flow of control.




Draw a flow-chart to identify whether a number taken as the input from the user is an even number or an odd number?



Pseudocode

·        Pseudocode is a way of representing an algorithm.


·        Pseudocode is not an actual program. So, it cannot be executed.

·        Some of the frequently used keywords while writing pseudocode are INPUT, COMPUTE, PRINT IF/ELSE, START, STOP


Advantages of Pseudo-Code:


·        Easily convertible to a Programming Language


·        Easy to understand and read


Write a pseudocode for identifying if a number is even or odd?

INPUT number A

COMPUTE remainder as r = A%2

IF r ==0 PRINT 'Even'

ELSE PRINT 'Odd'

Decomposition

Decomposition is the process of breaking a complex computer problem into smaller parts that are easily manageable and solvable.



 

Python Tutorial - 1 - Class 11 Computer Science - Introduction to Problem-Solving

Introduction to Problem-Solving

Problem and Problem Solving

In computer science, "problem" refers to a task or challenge that requires a solution. The process of identifying a problem, developing an algorithm, and implementing the algorithm to develop a computer program is called Problem Solving. Computers may be used to solve various daily life problems such as Train Ticket Booking, Online Shopping and Net-Banking etc.

Steps required for solving a problem

·        Analysing the problem

·        Developing an Algorithm

·        Coding

·        Testing and Debugging

Analyzing the Problem

This stage focuses on understanding the problem. If we do not have a clear understanding of the problem, we may develop a computer program that cannot solve the problem correctly. In this stage, we figure out the inputs, the outputs and the processing required to convert the input into the output.

Developing Algorithm

This stage focuses on creating a logical sequence of instructions, called an Algorithm. An algorithm has a distinct start and end point, as well as a defined number of steps. For a given problem, more than one algorithm may be possible and the most suitable algorithm may be chosen.

Algorithm for finding whether a number is Even or Odd

START

Step 1 → Take an integer number A

Step 2 → Divide A by 2, and store the remainder as r

Step 3 → If r is equal to 0, A is an Even Number

Step 4 → Else it is an Odd Number

STOP


Algorithm for finding whether a number is a Prime number or Not

START

Step 1 → Take an integer number A

Step 2 → Continuously divide A with integers ranging from 2 to A-1

Step 3 → If a is divisible by any value from 2 to A-1, it is not prime

Step 4 → Else it is prime

STOP

Coding

Coding is the process of creating computer programs.

Testing

Testing is a process to check if an application is working as expected (and not working abnormally). The main objective of Testing is to find errors.

Debugging

Debugging is the activity to fix the errors found in the application during the testing phase.

Representation of Algorithms

There are two common methods of representing an algorithm —flowchart and pseudocode.