55 lines
1.4 KiB
Markdown
55 lines
1.4 KiB
Markdown
#### Exercicios propostos no [CodeCheck](https://horstmann.com/codecheck/index.html)
|
|
___
|
|
## Ex 1.
|
|
height = 4.5<br />
|
|
width = 3<br />
|
|
volume1 = balloonVolume(width, height)<br />
|
|
print("Original volume: ", volume1)<br />
|
|
volume2 = balloonVolume(width + 1, height + 1)<br />
|
|
change = volume2 - volume1<br />
|
|
print("Change: ", change)<br />
|
|
change = balloonVolume(width + 2, height + 2) - volume2<br />
|
|
print("Change: ", change)
|
|
___
|
|
## Ex 2.
|
|
def balloonVolume(width, height):<br />
|
|
 pi = 3.1415926<br />
|
|
 a = height / 2<br />
|
|
 c = width / 2<br />
|
|
 volume = 4 * pi * a * c * c / 3<br />
|
|
 return volume
|
|
___
|
|
## Ex 3.
|
|
def hideCharacters(string) :<br />
|
|
 return "*" * len(string)
|
|
___
|
|
## Ex 4.
|
|
def isEven(n):<br />
|
|
 if n % 2 == 0:<br />
|
|
  return True<br />
|
|
 else:<br />
|
|
  return False<br />
|
|
<br />
|
|
def main() :<br />
|
|
 page = int(input("Enter page number: "))<br />
|
|
 if isEven(page) :<br />
|
|
  print(page)<br />
|
|
 else :<br />
|
|
  print("%60d" % page)<br />
|
|
<br />
|
|
main()
|
|
___
|
|
## Ex 5.
|
|
def countSpaces(string):<br />
|
|
 spaces = 0<br />
|
|
 for char in string:<br />
|
|
  if char == " ":<br />
|
|
   spaces += 1<br />
|
|
 return spaces<br />
|
|
<br />
|
|
def main() :<br />
|
|
 userInput = input("Enter a string: ")<br />
|
|
 spaces = countSpaces(userInput)<br />
|
|
 print(spaces)<br />
|
|
<br />
|
|
main() |