@TristinKeenan/

Aprendendo python 6

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
print('------------------------------0-------------------------------')
print("Given a string, delete all the characters @ from this string.")
print('--------------------------------------------------------------')

s1 = '[email protected]'

print(s1.replace('@',''))

print('------------------------------1-------------------------------') 
print("Given a string in which the letter h occurs at least twice, replace every occurrence of the letter h by the letter H, except for the first and the last ones.")
print('--------------------------------------------------------------')

s2 = "In the hole in the ground there lived a hobbit"
#meu
print(s2[:s2.find('h')]+(s2[s2.find('h'):s2.rfind('h')]).replace('h','H')+s2[s2.rfind('h'):])


#prof
'''
first_pos, last_pos = s.find('h') + 1, s.rfind('h')
left, middle, right = s[:first_pos], s[first_pos:last_pos], s[last_pos:]
print(left + middle.replace('h', 'H') + right)'''

print('------------------------------2-------------------------------') 
print("")
print('--------------------------------------------------------------')

s2 = 'Python'


#meu
for i2 in range(0,len(s2)):
  if i2%3!=0:
    print(s2[i2],end='')

print()
#prof
t2 = ''
for x2 in range(len(s2)):
  if x2 % 3 != 0:
    t2 += s2[x2]
print(t2)

print('------------------------------3-------------------------------')
print("For a given integer N, print all the squares of positive integers where the square is less than or equal to N, in ascending order.")
print('--------------------------------------------------------------')

print('Professor fez melhor \n')

a3 = 50
x3 = 1

#meu
while x3<=a3:
  if (x3*x3) <= a3:
    print(x3*x3)
  x3+=1
i3 = 1

#prof
while i3 ** 2 <= a3:
  print(i3 ** 2, end=' ')
  i3 += 1  
print()  




print('------------------------------4-------------------------------') 
print("Given an integer not less than 2. Print its smallest integer divisor greater than 1.")
print('--------------------------------------------------------------')

a4 = 15
i4 = 2
#meu/prof
while a4%i4!=0:
  i4+=1
print(i4)  

print('------------------------------5-------------------------------') 
print("For a given integer X, find the greatest integer n where 2ⁿ is less than or equal to X. Print the exponent value and the result of the expression 2ⁿ.")
print('--------------------------------------------------------------')
print("Soluçao estranha, tenho ctz q da pra fazer de forma mais eficiente talvez usando for \n")
a5 = 50
n5 = 0

#meu
while 2**n5 <= a5:
  n5+=1
n5-=1  
print(n5, 2**n5) 

#prof

while 2 ** n5 <= a5:
  n5 += 1
print(n5 - 1, 2 ** (n5 - 1))

print('------------------------------6-------------------------------') 
print("As a future athlete you just started your practice for an upcoming event. On the first day you run x miles, and by the day of the event you must be able to run y miles.\
Calculate the number of days required for you to finally reach the required distance for the event, if you increases your distance each day by 10% from the previous day.\
Print one integer representing the number of days to reach the required distance.")
print('--------------------------------------------------------------')

a6 = 10
b6 = 30
c6 = 1

#meu/prof
if a6<b6:
  while a6<b6:
    a6*=1.1
    c6+=1
print(c6)  

print('------------------------------7-------------------------------') 
print("Given a sequence of non-negative integers, where each number is written in a separate line. Determine the length of the sequence. The sequence ends with 0. Print the length of the sequence (not counting the 0). The numbers following the number 0 should be omitted.")
print('--------------------------------------------------------------')

print("caraca o meu codigo ficou mto melhor,(FINALMENTE)")
a7 = 0
'''
#meu
while int(input()) != 0:
  a7+=1
print(a7)  

#prof
a = int(input())
length = 0
while a != 0:
  a = int(input())
  length += 1
print(length)
'''
print('------------------------------8-------------------------------') 
print("Given a sequence of non-negative integers, where each number is written in a separate line. The sequence ends with 0. Print the sum of the sequence.")
print('--------------------------------------------------------------')
'''
a8 = int(input())
b8 = 0

#meu/prof
while a8 != 0:
  b8 += a8
  a8 = int(input())
print(b8)  
'''
print('------------------------------9-------------------------------') 
print("Given a sequence of non-negative integers, where each number is written in a separate line. The sequence ends with 0. Print the average of the sequence. ")
print('--------------------------------------------------------------')

'''
a9 = int(input())
b9 = 0
c9 = 0

while a9 != 0:
  b9 += a9
  a9 = int(input())
  c9+=1
print(b9/c9)  
'''