0% found this document useful (0 votes)
8 views19 pages

Computer Science Assignement 1

The document contains various Python code snippets demonstrating basic programming concepts such as calculating simple interest, finding the greatest common divisor (GCD), generating multiplication tables, and checking for prime numbers. It includes user input prompts and calculations for tasks like summing natural numbers, determining leap years, and calculating factorials. The code examples are executed in Python 3.12.4 on a Windows environment.

Uploaded by

sdivyam418
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views19 pages

Computer Science Assignement 1

The document contains various Python code snippets demonstrating basic programming concepts such as calculating simple interest, finding the greatest common divisor (GCD), generating multiplication tables, and checking for prime numbers. It includes user input prompts and calculations for tasks like summing natural numbers, determining leap years, and calculating factorials. The code examples are executed in Python 3.12.4 on a Windows environment.

Uploaded by

sdivyam418
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 19
Fython 3.12.4 (tags/v3.12.4:GeGadba, dun 6 2024, 19:30:16) [msc v.1940 64 bit ( « AMDO4)] on win32 ‘type "help", “copyright, "credits" or “license()" for more information. coo RESTART: C:/Users/divya/py.q4-py Enter the principal amount: 200 Enter the rate of interest (as a percentage): 40 Enter the cine in years: 900 Simple Interest: 72000.(] py.a.py - C/Users/divya/py.c4py (3.124) File Edit Format Run Options Window Help principal = float (input ("Enter the principal amount: ")) rate = float (input ("Enter the rate of interest (as 4 percentage): ")) time = float (input ("Enter the time in years: ")) simple_interest = (principal * rate * time) / 100 eine ("Single Invexest:", simple incezest)] A qI9.py - C/Users/aivya/qtS.py (3.12.4) File Edit Format Run Options Window Help def gcd(x, y) while (yI my return x def lom(x, y): return abs (xy) // gcd(x, y) nomi num int (input ("Enter first number: ")) int (input ("Enter second number: "}) print("The LCM of", numl, "and", num2, "is" lcm(numl, num2)) IDLEShell 3.12.4 File Edit Shell Debug Options Window Help Python 3.12.4 (tags/v3.12.4:8e8adba, dun 6 2024, 19:30:16) [msc v.194¢ amDe4)] on win32 Dype "help", "copyright", "credits" or "license()" for more informatior C:/Users/divya/al3.py Enter the number to print the multiplication table: 8 z1s8 16 24 32 40 48 56 4 72 80 HOMO KO 1 2 3 4 5 6 5 8 9 1 = A qiBpy - CyUsers/aivya/q1@.py (2.124) - oa File Edit Format Run Options Window Help number = int (input ("Enter the number to print the multiplication table: ")) # Define the range of the multiplication table table range = 10 4 Print the multiplication table for fin renge(1, table range + 1): peint (nummer, "x", , munber * iy] - oOo x [A IDLE Shen 3.124 File _Edit_Shell Debug Options _Window Help eython 3.12.4 (tags/v3.12.4:Seadba, dun 6 2024, 1 Amp6s Type Enter the number of terms: ‘The sum of the first 673049 natural numbers is: 226497814725 16) [usc v.1940 64 bit ( « 1} on wins2 "help", "copyright", "credits" or "license()" for more information. RESTART: C:/Users/divya/py. q 16.pY 673049 In7 Cobo 4. py. 4 16py -CiUsers/divyarpy. a T6xpy @.124) - ox Fle edit Format Run Options Window Help Y= int (input ("enter the number of teras: *) sum_of_natural_numbers =n * (n+ 1) // 2 print ("The sum of the first", n, "natural numbers is:", sum_of_natural_numbers) A IDLE Shell 212.46 - a »* ile Edit Shell Debug Options Window Help Python 3.12.4 (tags/v3.12.4:Se8adba, Jun 6 2024, 19: AMD64)] on win32 ‘Type "help", "copyright", “credits” or “license()" for more information. >>| pie) (MSC v.1040 €4 bit ( RESTART: C:/Users/divya/py. gll.py enter a number: 69 The sum of the digits of 69 is: 15 >| A PY. O9.y - C/Users/adya/PY. 3.py 3.12.4) - oo x File Edit Format Run Options Window Help year = int (input ("Enter a year: ")) if (year #4 == 0 and year % 100 != 0) or (year % 400 == 0): print(year, "is a leap year") else print(year, "is not a leap year") IDLE Shell 2.124 - a File Edit Shell Debug Options Window Help Fython 3.12.4 (tags/v3.12.4:SeSadba, gun € 2024, 18:30:16) [usc v.1940 64 bit aDé4)] on win32, Type “help", "copyright", “credits” or “license()" for more information. > RESTART: C:/Users/divya/py-q7-EY moter a number: 40 40 is Even »>>|| 1 PY.GL.by - G/UseIs/anyarpy.qr-py (3.124) ile Edit Format Run Options Window Help umber = int (input ("Enter a number: ")) Check if the number is even or odd = number % 2 O: print (number, "is Even") lse: print (number, "is odd") a wie snen size - uw Fle Edit Shel Debug Options Window Help Python 2.12.4 (tags/v2.12.4:Getadba, Sun € 2024, 18:30:16) (Mac v.140 64 bit Gedy)» on wind? type "help", "copyright", "credits" or "License ()" for more information, RESTART: C2/Usere/divya/py.26.BY Enter a number: 65 me square of 65.0 is: 4225.0 >>|] & py.a6.py - C:/Users/divya/py.q6.py (3.12.4) File Edi(ocatotme pe ?_OPtions Window Help yumber ut ("Enter a number: ")) square = number ** 2 orint ("The square of", number, "is square) File Edit Format Run Options Window Help vase = float (input ("Enter the base number: ")) >xponent = int(input("Enter the exponent (positive integer): ")) result = 1 for _ in range (exponent): Fesult *= base orint(f" {base} to the power of {exponent} is: {result)") A IDLE Shetl3.124 - o x File Edit Shell Debug Options _ Window Help Python 3.12.4 (tags/v3.12.4:8e8adba, Jun 6 2024, 19:30:16) [MSC v.1640 64 bit ( aypé4)} on win32 ‘Type "help", "copyright", "credits" or “License()" for more information. RESTART: C:/Users/divya/q 22.py enter the base number: 99 Enter the exponent (positive integer): 7 2-0 te the power of 7 is: 93206534790699.0 poe > IDLE Shell 3.124 - o x File Edit Shell Debug Options Window Help. python 3.12.4 (tags/v3.12.4:8eadba, gun 6 2024, 19:30:16) [MSC v.i940 64 bit ( BMpE4)} on win32 ‘Type "help", "copyright", "credits" or icense()" for more information. RESTART: C:/Users/divya/q21-py Enter a number: 74246654 ‘The number of digits is: 9 ile_Edit_ Format Run Options Window Help umber = int (input ("Enter @ number: ")) ount = 0 nile number number /) count #21 rint ("The number of digits is:", count) A IDLEShell 3.124 - ou x File Edit Shell Debug Options Window Help python 3.12.4 (tags/v3.12.4:SeGadba, gun 6 2024, 19:30:16) (WSC v.1940 64 bit (+ AMDO4)] on win3z Type "help", "copyright", “credits” or "license()" for more information. /Users/divya/qls.py ESTAR! Enter first mumber: 65 Enter second number: 89 The LEM of €5 and 9 is S765 >>| pune si ate File Edit Shell Debug Options Window Help Python 3.12.4 (tags/v3.12.4:GeGadba, Jun € 2024, 19:30:16) [MSC v.1040 64 bit aMDo4)] on win32 ‘Type "help", "copyright", "credits" or "License()" for more information. >> = RESTART: C:/vsers/divya/py.g 15.py Enter a number: 2 2 is a prime number > A pyg 15py - C/Users/divya/py 15.py (3.124) File Edit Format Run Options Window Help number = int (input ("Enter 2 number: ")) ds _prime = roe Af number > 1: for i in range(2, int (number ** 0.5) + 1): if (number 3 i) == 0: is prime = raise break else: is prime = False af is prime: print (number, "is a prime number") else: print (number, "is not a prime number" ile Edit Shell Debug Options Window Help Fython 3.12.4 (tags/v3.12.4:SeBadba, gun 6 2024, 1 ampé4)] on win32 ‘Type "help", "copyright", "credits" or "License()" for more information. 16) (MSC v.iS40 64 bit (4 RESTART: C:/Users/divya/q13.py Enter a number: 09547 9547 is nov an Amscrong number >I 2 at3py - C/Users/divya/at3.py (3.12.4) - o x le _Eoit Format Run Options Window Help jumber = int (input (Enter a number: ")) spiginal_number = number rum_of_digits = 0 yum_of digits = len(str(number)) guile Humber > 0: digit = number % 10 sum_of_digits += digit ** num of digits number //= 10 © oviginal_nunber == sum_of digits: print (oFiginal_number, "Is an Armstrong number") print (original_number, "is not an Armstrong number") A wuts one s.124 File Edit Shell Debug Options Window _Help Bython 3.12.4 (tags/v3.12.4:Ge0adba, Gun 6 2024, 19:30:16) (MSC v.1540 64 bit ( « ‘AMD64)] on win32 Type "help", "copyright", "credits" or "License()" for more information. RESTART: C: /Users/divya/py.q12.py Enter = number: 8309 The reversed number is: 9038 >>|] py lepy - Grusersvunyarpysdtey (3.12 File Edit Format Run Options Window Help, number = int (input ("enter a number: ")) reversed_number = int (str (number) [::-1]) print ("the reversed number is:", reversed number) se wuce sien o.1cat File Edit Shell Debug Options Window Help ychen 9.12.4 Gage/r2.i2.4rvetadba, san 6 2024, 1830718 DSS ¥.I8E0 6 DET ( Bube#) ) on wins tyre "help", "copyright", "credits" or "License()" for more information. Enter a number: 600 The ‘the The the The The The The The The The The The The The The the The the The the The the The the The The The The The The The The The factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial factorial 800 4 800 800 800 800 800 i 800 800 i 800 800 & 800 800 & 800 800 & 800 800 4 800 800 4 800 800 4 200 800 i 800 800 800 800 800 i 800 800 & 800 800 & 800 800 & 800 ESTAR users/divya/eY.gl0.py 24 120 720 5040) 40320 362880 3628800 39916900 479001600 6227020800 87178231200 1307674368000 2922789888000 3556874280960 6402373705728000 121645100408832000 2432902008176640000 51090942171709440000 1124000727777607680000 25852016738884976640000 620449401733229499360000 15511210043330985924000000 403291461126605695524000000 19888869450418352160768000000 304e¢8244611719860501504000000 8641761993739701954543616000000 26525205981219105862620460000000 8222838654177922617725562880000000 262130036922689530167218012160000000 8683317618611986495518194401260000000 29523279903460414084761609642520000000 Unt Cok & PY.Q1D,py - C/Users/divya/PY.Q10 py (3.12.4) - 1 File Edit Format Run Options Window Help number = int (input ("Enter a number: ")) factorial = 1 for i in range(1, number + 1): factorial *= i print("The factorial of", number, “is:", factorial)| IDLE she 3.124 - ao x le fit Shell Debug Options Window Help bython 3.12.4 (tags/v3.12.4:GeGadba, Jun 6 2024, 18:30:16) (MSC v.1S40 64 bit ( « AEDEA)] on win32 ‘Type "help", "copyright", "credits" or “license()" for more information. = RESTART: C:/Users/divya/PY. 99.py Enter a year! 2008 2008 is a leap year tLe snen 3124 - u » File Edit Shell Debug Options Window Help python 3.12.4 (tags/v3.12.4:8e8adba, sun 6 2024, 19:30:16) [MSC v.1940 64 bit ( ‘aND64)] on win32 ‘Type "help", "copyright", “credits” or “license()" for more information. wane nnstart: 0: /ts0rs/divya/P¥.98-py Enter the first number: 900 Enter the second nunber: £00 Enter the third number: 1000 The largest number is: 1000.0 »>|| A. PV.08 py - C/Users/dvya/PY.O8 py (2.12.4) - a File Edit Format Run Options Window Help aumber] = float (input ("snter the first number: ")) aumber2 = float (input ("snter the second number: ")) sumber3 = float (input ("Enter the third number: ")) largest = max(numberl, number2, number3) print ("The largest number is:*, largest)| ile Edit Shell Debug Options Window Help Fython 3.12.4 (tags/v3.12.4:GeGadba, Jun 6 2024, 19:30:16) [Msc v.1940 6¢ bit ( AMDE4)] on win32 ‘Type "help", "copyright", "credits" or "Llicense()" for more information. > RESTART: C:/Users/divya/py.a5.py Enter the temperature in Celsius: 23 Temperature in Fahrenheit: 73.4 FP BY 2by ~ Ly USEIS/UIIYAY Hy-UOPY (214) File Edit Format Run Options Window Help celsius = float Gnput ("Enter the temperature in Celsius: ")) # Convert to Fahrenheit fahrenheit = (celsius * 9/5) + 32 # Print the result print ("Temperature in Fahrenheit:", fahrenheit) A IDLE Shell 3.124 - ao x File Edit Shell Debug Options Window Help Python 3.12.4 (tags/v3.12.4:eBadba, Jun € 2024, 19:30:16) [MSc v.iS40 64 bit ( ‘AMD64)] on win32 rype "help", "copyright", "credits" or "License ()" for more information. RESTART: C: /Users/divya/py.add, div,multiply.py Enter the first number: 2 Enter the second number: 6 Addition: 6.0 Subtraction: 4.0 Multiplication: 12.0 Division: 0.2333333333223323 >>>!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy