You are on page 1of 5

1 cities = ['Berlin', 'São Paulo', 'Tokyo', 'New York']

2 capitals = ['Berlin', 'Tokyo']


3 for city in cities:
4 # If the current city is not a capital, continue with the next city
5 if city not in capitals:
6 continue
7 print(f'{city} is a capital')

semi_annual_raise

r = 0.04 0.25

annual_salary
portion_saved
total_cost
semi_annual_raise

Enter your starting annual salary: 120000


Enter the percent of your salary to save, as a decimal: . 05
Enter the cost of your dream home: 500000
Enter the semiannual raise, as a decimal: .03
Number of months: 142

Enter your starting annual salary: 80000


Enter the percent of your salary to save, as a decimal: . 1
Enter the cost of your dream home: 800000
Enter the semiannual raise, as a decimal: .03
Number of months: 159

Enter your starting annual salary: 75000


Enter the percent of your salary to save, as a decimal: . 05
Enter the cost of your dream home: 1500000
Enter the semiannual raise, as a decimal: .05
Number of months: 261

Version 1 :

Main Algorithm V1
Variables
string Sequence / vector of char
string Pattern
integer cp
integer i
Begin
Write("Enter a sequence")
Sequence <- read()
Write("Enter a pattern")
Write("Enter a pattern")
Pattern <- read()
for i <-0 to length(Sequence)-length(Pattern) do
b <- checkPattern(i,Sequence,Pattern)
if b = true then
cp <- cp + 1
endif
endfor
End

Function b <- checkPattern(k,s,p)


Input
integer k
string s
string p
Output
boolean b
Variable
integer i
Begin
b <- true
for i <-0 to length(p) do
if s[k+i] != p[i] then
b <- false
endif
endfor
return b
End

Version 2 :

1) on character pattern

Main Algorithm v2-1


Variables
character Sequence
character Pattern
integer cp
integer i
Begin
cp <- 0
Write("Enter a pattern")
Pattern <- read()
Sequence <- read()
while Sequence != '.' do
if Sequence = Pattern then
cp <- cp + 1
Sequence <- read()
endwhile
End

2) two characters pattern

Main Algorithm v2-2


Variables
string Pattern
character c0,c1
integer cp
integer i
Begin
cp <- 0
Write("Enter a pattern")
Pattern <- read()
Pattern <- read()
c0 <- '.'
c1 <- '.'
c1 <- read()
while c1 != '.' do
if c0 = Pattern[0] and c1 = Pattern[1] then
cp <- cp + 1
c0 <- c1
c1 <- read()
endwhile
End

3) any characters pattern

Main Algorithm v2-3


Variables
string History
string Pattern / vector of character
integer cp
integer i
Begin
cp <- 0
Write("Enter a pattern")
Pattern <- read()
for i <-0 to length(Pattern) do
History[i] <- '.'
endfor
History <- update_and_read(History)
while History[length(History]-1] != '.' do
if check(History,Pattern) then
cp <- cp + 1
History <- update_and_read(History)
endwhile
End

Function b <- check(h,p)


Input
string h
string p
Output
boolean b
Variable
integer i
Begin
b <- true
for i <-0 to length(p) do
if h[i] != p[i] then
b <- false
endif
endfor
return b
End

Function h <- update_and_read(h)


Input
string h
character c
Output
string h
Variable
integer i
Begin
for i <-0 to length(h)-1 do
for i <-0 to length(h)-1 do
if h[i] <- h[i+1]
endfor
h[length(h)-1] <- read()
return h
End

You might also like