Skip to content

TeacherRoot/PythonLoopPractice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

PythonLoopPractice

Exercise to practice loops in Python

Assignment 1

Lab Goal : This lab will focus on decision making and iteration [ looping ] while reviewing accessing numeric digits using mod and divide.

Lab Description : Write a program that will count up how many digits a number contains. You must use a loop and use / to reduce the number so that you can count all of the digits.

Sample Data :

234
10000
111
9005
84645
8547
123456789
5555672468
2548522125455
2545588514548
111111111
121212121212

Sample Output :

3
5
3
4
5
4
9
10
13
13
9
12

Assignment 2

Lab Goal : This lab will focus on decision making and iteration [ looping ] while reviewing accessing numeric digits using mod and divide.

Lab Description : Write a program that will sum all of a numbers digits. You must use % for this lab to access the right most digit of the number. You will use / to chop off the right most digit.

Sample Data

234
10000
111
9005
84645
8547
123456789
5555672468
2548522125455
2545588514548
111111111
121212121212

Sample Output

9
1
3
14
27
24
45
53
50
64
9
18

Assignment 3

Lab Description : Write a program that will average all of a numbers digits. You must use % for this lab to access the right most digit of the number. You will use / to chop off the right most digit.

Sample Data

234
10000
111
9005
84645
8547
123456789
5555672468
2548522125455
2545588514548
111111111
121212121212

###Sample Output
3.0
0.2
1.0
3.5
5.4
6.0
5.0
5.3
3.8461538461538463
4.923076923076923
1.0
1.5

Assignment 4

Lab Goal : This lab will focus on decision making and iteration [ looping ] while reviewing accessing numeric digits using mod and divide.

Lab Description : Write a program that will count all of a numbers even digits. You must use % for this lab to access the right most digit of the number. You will use / to chop off the right most digit. You will also need to use % mod to check for remainders to determine odd or even.

Sample Data

234
10000
111
9005
84645
8547
123456789
5555672468
2548522125455
2545588514548
111111111
121212121212

Sample Output

2
4
0
2
4
2
4
5
7
7
0
6

Assignment 5 Is Cool

Lab Goal : This lab will focus on loops, decision making, and methods.

Lab Description : Complete methods isCoolNum( n ) && countCoolNumbers( n ). isCoolNum( n) will determine if a number is a cool number. A cool number is any number that has a remainder of 1 when divided by 3,4,5, and 6. countCoolNumbers will count the number of cool numbers between 6 and the parameter passed in.

Sample Data
250
1250
2250
5500
9500
23500
32500

Sample Output :
4 cool numbers between 6 - 250
20 cool numbers between 6 - 1250
37 cool numbers between 6 - 2250
91 cool numbers between 6 - 5500
158 cool numbers between 6 - 9500
391 cool numbers between 6 - 23500
541 cool numbers between 6 - 32500

Assignment 6

Lab Goal : This lab was designed to teach you more about nested loops and conditions.

Lab Description : Write a program that will read in a number and then print out a triangle of #s using nested loops.

Sample Data
1
2
3
4
9
12

Sample Output

#

#

##


#

##

###

#

##

###

####

#

##

###

####

#####

######

#######

########

#########

#

##

###

####

#####

######

#######

########

#########

##########

###########

############

Assignment 7

Lab Goal : This lab was designed to teach you more about nested loops and conditions.

Lab Description : Write a program that will read in a number and then print out a triangle of #s using nested loops.

Sample Data 1
2
3
4
9
12

Sample Output

# </p>

     # </p>
    ## </p>
   ### </p>
  #### </p>
 ##### </p>
###### </p>

#######

########

#########

        # </p>
       ## </p>
      ### </p>
     #### </p>
    ##### </p>
   ###### </p>
  ####### </p>
 ######## </p>
######### </p>

##########

###########

############

Assignment 8 HACKER

Lab Description : Write a program that will read in a number and then print out a triangle of #s using nested loops.

Sample Data 1
2
3
4
9
8

Sample Output 1

11
2

111
22
3

1111
222
33
4

111111111
22222222
3333333
444444
55555
6666
777
88
9

11111111
2222222
333333
44444
5555
666
77
8

Assignment 9 HACKER

Lab Goal : This lab was designed to teach you how to use nested loops. You will also learn how to make some cool shapes.

Lab Description : Used nested loops to print out a letter pattern as shown below. Wrap around the letters from Z to A. You will need to know the ASCII values of capital letters.

Sample Data :
4 C
5 A
7 B
6 X
8 Z

Sample Output :
CCCC DDD EE F
CCCC DDD EE
CCCC DDD
CCCC

AAAAA BBBB CCC DD E
AAAAA BBBB CCC DD
AAAAA BBBB CCC
AAAAA BBBB
AAAAA

BBBBBBB CCCCCC DDDDD EEEE FFF GG H
BBBBBBB CCCCCC DDDDD EEEE FFF GG
BBBBBBB CCCCCC DDDDD EEEE FFF
BBBBBBB CCCCCC DDDDD EEEE
BBBBBBB CCCCCC DDDDD
BBBBBBB CCCCCC
BBBBBBB

XXXXXX YYYYY ZZZZ AAA BB C
XXXXXX YYYYY ZZZZ AAA BB
XXXXXX YYYYY ZZZZ AAA
XXXXXX YYYYY ZZZZ
XXXXXX YYYYY
XXXXXX

ZZZZZZZZ AAAAAAA BBBBBB CCCCC DDDD EEE FF G
ZZZZZZZZ AAAAAAA BBBBBB CCCCC DDDD EEE FF
ZZZZZZZZ AAAAAAA BBBBBB CCCCC DDDD EEE
ZZZZZZZZ AAAAAAA BBBBBB CCCCC DDDD
ZZZZZZZZ AAAAAAA BBBBBB CCCCC
ZZZZZZZZ AAAAAAA BBBBBB
ZZZZZZZZ AAAAAAA
ZZZZZZZZ

About

Exercise to practice loops in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages