jueves, 19 de septiembre de 2024

List exercises


Below are a set of scores that students have received in the past semester. Write code to determine how many are 90 or above and assign that result to the value a_scores.


 scores = "67 80 90 78 93 20 79 89 96 97 92 88 79 68 58 90 98 100 79 74 83 88 80 86 85 70 90 100"

a_scores=len([c for c in [ int(a) for a in scores.split()] if c>=90])


Write code that uses the string stored in org and creates an acronym which is assigned to the variable acro. Only the first letter of each word should be used, each letter in the acronym should be a capital letter, and there should be nothing to separate the letters of the acronym. Words that should not be included in the acronym are stored in the list stopwords. For example, if org was assigned the string “hello to world” then the resulting acronym should be “HW”.


stopwords = ['to', 'a', 'for', 'by', 'an', 'am', 'the', 'so', 'it', 'and', "The"]

org = "The organization for health, safety, and education"

acro=[a[0].upper() for a in org.split() if a not in stopwords]

acro=''.join(acro)

print(''.join(acro))



-------------

p_phrase = "was it a car or a cat I saw"


# Reverse the original phrase, keeping the spaces and case

r_phrase = p_phrase[::-1]


# Check if the original phrase is equal to the reversed version

is_palindrome = p_phrase.replace(" ", "").lower() == r_phrase.replace(" ", "").lower()


# Print the results

print("Original phrase:", p_phrase)

print("Reversed phrase:", r_phrase)

print("Is palindrome:", is_palindrome)


No hay comentarios:

Publicar un comentario