Difference between revisions of "Python Problems and Solutions"

From rbachwiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 29: Line 29:
     else:
     else:
         print(i)
         print(i)
==[[#top|Back To Top]] - [[Python|Category]]==
[[Category:Python]]

Latest revision as of 16:20, 1 September 2020

st = 'Print only the words that start with s in this sentence'
for word in st.split():
    if word[0].lower()== 's':
     print(word)

Use Range() to print all even numbers from 0 to 10

for num in range(0,11,2):
  print(num)

Or using Modulos

for i in range(0,11)
 if i%2 ==0:
 print(i)

Go through the string below and if the length of a word is even print "even!"

st = 'Print every word in this sentence that has an even number of letters'
for i in st.split():
 if len(i) % 2 ==0:
  print(i + "is even")

Write a program that prints the integers from 1 to 100. But for multiples of three print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

for i in range(0,50):
   if i%3 == 0 and i%5 ==0:

print("fizz")

   elif i%3 == 0:
       print("buzz")
   elif i%5 ==0:
       print("yes")
   else:
       print(i)

Back To Top - Category