SlideShare a Scribd company logo
1 of 1
Q1. (5 points) Write a short program that simplifies the following code so that it does not use any
break or continue statements, yet the logic is equivalent, and the code outputs the counter value
of 126. counter = 0 while True: if counter >= 100 : break elif counter %2 = 0 : counter + = 1
continue else: counter = 2 ; continue print("counter:", counter) Q2. (5 points) Write a short
program that will: - prompt the user for a number - print out whether the number is a perfect
square and then end the program - prompt the user for another number if the input was not a
perfect square Suggestion: Import the math module and use the sqrt() function to find the square
root of a number. Example: import math math.sqrt(some_number) Sample Output:
============== Perfect Squares ============= Enter a number: 40 Not a perfect square.
Enter a number: 60 Not a perfect square. Enter a number: 100 100 is a perfect square. Q3. (5
points) Write a short program that prompts the user for an integer and prints the integer, but if
something other than an integer is input, the program keeps asking for an integer. Sample
Output: Enter an integer: a Enter an integer: a Enter an integer: b Enter an integer: % Enter an
integer: 3 The integer is: 3 Deliverable:

More Related Content

Similar to Q1- (5 points) Write a short program that simplifies the following cod.docx

Similar to Q1- (5 points) Write a short program that simplifies the following cod.docx (20)

Programming Fundamental handouts
Programming Fundamental handoutsProgramming Fundamental handouts
Programming Fundamental handouts
 
03b loops
03b   loops03b   loops
03b loops
 
Lab-11-C-Problems.pptx
Lab-11-C-Problems.pptxLab-11-C-Problems.pptx
Lab-11-C-Problems.pptx
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Cp manual final
Cp manual finalCp manual final
Cp manual final
 
17 Jo P May 08
17 Jo P May 0817 Jo P May 08
17 Jo P May 08
 
A01
A01A01
A01
 
c++ Question
c++  Questionc++  Question
c++ Question
 
prathamesh .ppt 1.pptx
prathamesh  .ppt 1.pptxprathamesh  .ppt 1.pptx
prathamesh .ppt 1.pptx
 
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORYGE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
GE3171-PROBLEM SOLVING AND PYTHON PROGRAMMING LABORATORY
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 
Computer experiments 1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
Computer experiments   1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branchComputer experiments   1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
Computer experiments 1^j2^j3^j4^j8^j9. d24 ^j sakshi gawade cs branch
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
Oop lab assignment 01
Oop lab assignment 01Oop lab assignment 01
Oop lab assignment 01
 
c++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdfc++ exp 1 Suraj...pdf
c++ exp 1 Suraj...pdf
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 
COMP 122 Entire Course NEW
COMP 122 Entire Course NEWCOMP 122 Entire Course NEW
COMP 122 Entire Course NEW
 
Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3
 
Csci101 lect03 algorithms_i
Csci101 lect03 algorithms_iCsci101 lect03 algorithms_i
Csci101 lect03 algorithms_i
 

More from sngyun4t79

More from sngyun4t79 (20)

Presented below is information for Wildhorse Corp-- for the year 2025-.docx
Presented below is information for Wildhorse Corp-- for the year 2025-.docxPresented below is information for Wildhorse Corp-- for the year 2025-.docx
Presented below is information for Wildhorse Corp-- for the year 2025-.docx
 
Practice the following diagnostic statements using your Manual ICD-10.docx
Practice the following diagnostic statements using your Manual  ICD-10.docxPractice the following diagnostic statements using your Manual  ICD-10.docx
Practice the following diagnostic statements using your Manual ICD-10.docx
 
Potentials Question 15 Unanswered Hypokalemia (low extracellular K+ co.docx
Potentials Question 15 Unanswered Hypokalemia (low extracellular K+ co.docxPotentials Question 15 Unanswered Hypokalemia (low extracellular K+ co.docx
Potentials Question 15 Unanswered Hypokalemia (low extracellular K+ co.docx
 
Practice Management or Electronic Health Record- As a healthcare profe.docx
Practice Management or Electronic Health Record- As a healthcare profe.docxPractice Management or Electronic Health Record- As a healthcare profe.docx
Practice Management or Electronic Health Record- As a healthcare profe.docx
 
Prance- Inc-- earned pretax book net income of $941-000 in 2020- Pranc.docx
Prance- Inc-- earned pretax book net income of $941-000 in 2020- Pranc.docxPrance- Inc-- earned pretax book net income of $941-000 in 2020- Pranc.docx
Prance- Inc-- earned pretax book net income of $941-000 in 2020- Pranc.docx
 
ppl ppl ppl Match each ecosystem-biome with its traditional mone.docx
ppl ppl ppl       Match each ecosystem-biome with its traditional mone.docxppl ppl ppl       Match each ecosystem-biome with its traditional mone.docx
ppl ppl ppl Match each ecosystem-biome with its traditional mone.docx
 
Prepare Common-size financials for the Balance Sheet and Income Statem.docx
Prepare Common-size financials for the Balance Sheet and Income Statem.docxPrepare Common-size financials for the Balance Sheet and Income Statem.docx
Prepare Common-size financials for the Balance Sheet and Income Statem.docx
 
Q10- A person has inhaled carbon monoxide CO poisoning- CO has an ext.docx
Q10- A person has inhaled carbon monoxide  CO poisoning- CO has an ext.docxQ10- A person has inhaled carbon monoxide  CO poisoning- CO has an ext.docx
Q10- A person has inhaled carbon monoxide CO poisoning- CO has an ext.docx
 
Python Create 3 variables named- userName result userNum Prompt the u.docx
Python Create 3 variables named- userName  result userNum Prompt the u.docxPython Create 3 variables named- userName  result userNum Prompt the u.docx
Python Create 3 variables named- userName result userNum Prompt the u.docx
 
Python coding Question Assume the availability of a function is_prime-.docx
Python coding Question Assume the availability of a function is_prime-.docxPython coding Question Assume the availability of a function is_prime-.docx
Python coding Question Assume the availability of a function is_prime-.docx
 
Puerto Rico has been devastated by hurricane Maria- Three weeks after.docx
Puerto Rico has been devastated by hurricane Maria- Three weeks after.docxPuerto Rico has been devastated by hurricane Maria- Three weeks after.docx
Puerto Rico has been devastated by hurricane Maria- Three weeks after.docx
 
public static void main(String-- args) { int i- int-- list - {0-1-0-4-.docx
public static void main(String-- args) { int i- int-- list - {0-1-0-4-.docxpublic static void main(String-- args) { int i- int-- list - {0-1-0-4-.docx
public static void main(String-- args) { int i- int-- list - {0-1-0-4-.docx
 
Provide an example of an evervday material that is linearly elastic Pr.docx
Provide an example of an evervday material that is linearly elastic Pr.docxProvide an example of an evervday material that is linearly elastic Pr.docx
Provide an example of an evervday material that is linearly elastic Pr.docx
 
Proteins in the blood plasma involved in hemostasis include Albumins A.docx
Proteins in the blood plasma involved in hemostasis include Albumins A.docxProteins in the blood plasma involved in hemostasis include Albumins A.docx
Proteins in the blood plasma involved in hemostasis include Albumins A.docx
 
Proteins that lack a vacuolar localization signal will be secreted int.docx
Proteins that lack a vacuolar localization signal will be secreted int.docxProteins that lack a vacuolar localization signal will be secreted int.docx
Proteins that lack a vacuolar localization signal will be secreted int.docx
 
Protective factors are anything that supports mental health and wellbe.docx
Protective factors are anything that supports mental health and wellbe.docxProtective factors are anything that supports mental health and wellbe.docx
Protective factors are anything that supports mental health and wellbe.docx
 
Protein Structure - Briefiy explain the dynamics between amino ocid se.docx
Protein Structure - Briefiy explain the dynamics between amino ocid se.docxProtein Structure - Briefiy explain the dynamics between amino ocid se.docx
Protein Structure - Briefiy explain the dynamics between amino ocid se.docx
 
project 1 - ARP table extraction- the first part of the program must h.docx
project 1 - ARP table extraction- the first part of the program must h.docxproject 1 - ARP table extraction- the first part of the program must h.docx
project 1 - ARP table extraction- the first part of the program must h.docx
 
PROJECT MANAGEMENT ASSIGNMENT Tell me a project example from your expe.docx
PROJECT MANAGEMENT ASSIGNMENT Tell me a project example from your expe.docxPROJECT MANAGEMENT ASSIGNMENT Tell me a project example from your expe.docx
PROJECT MANAGEMENT ASSIGNMENT Tell me a project example from your expe.docx
 
Positive directional linear selection on a trait always results in the.docx
Positive directional linear selection on a trait always results in the.docxPositive directional linear selection on a trait always results in the.docx
Positive directional linear selection on a trait always results in the.docx
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 

Q1- (5 points) Write a short program that simplifies the following cod.docx

  • 1. Q1. (5 points) Write a short program that simplifies the following code so that it does not use any break or continue statements, yet the logic is equivalent, and the code outputs the counter value of 126. counter = 0 while True: if counter >= 100 : break elif counter %2 = 0 : counter + = 1 continue else: counter = 2 ; continue print("counter:", counter) Q2. (5 points) Write a short program that will: - prompt the user for a number - print out whether the number is a perfect square and then end the program - prompt the user for another number if the input was not a perfect square Suggestion: Import the math module and use the sqrt() function to find the square root of a number. Example: import math math.sqrt(some_number) Sample Output: ============== Perfect Squares ============= Enter a number: 40 Not a perfect square. Enter a number: 60 Not a perfect square. Enter a number: 100 100 is a perfect square. Q3. (5 points) Write a short program that prompts the user for an integer and prints the integer, but if something other than an integer is input, the program keeps asking for an integer. Sample Output: Enter an integer: a Enter an integer: a Enter an integer: b Enter an integer: % Enter an integer: 3 The integer is: 3 Deliverable: