CITS2401 Written Exam Questions Correctly Answered.
CITS2401 Written Exam Questions Correctly Answered. Write a function count_word(sentence, word) that takes 'sentence' and 'word' as parameters and returns the number of times the 'word' appears in 'sentence'. You may assume the string has at least one character in it. - CORRECT ANSWER def count_word(sentence, word): return (word) Write a function is_a_number(string) that takes a string as a parameter and returns True if the string is an integer value, otherwise returns False. You may assume the string has at least one character in it. - CORRECT ANSWER def is_a_number(string): return eric() Write a function replace_character(sentence) that takes a parameter 'sentence' returns a new string where all letters 's' and 'S' are replaced with '$'. You may assume the string has at least one character in it. - CORRECT ANSWER def replace_character(sentence): return ce("S", '$').replace('s', '$') Write a function top_and_tail(string) that takes a string as a parameter and returns the string with its first and last characters removed. You may assume the string has at least one character in it. - CORRECT ANSWER def top_and_tail(string): return string[1:-1] Write a function half_string(string) that takes a string as a parameter and returns the first half of the string. You may assume the string has at least one character in it. If the string length is odd, then you may assume it returns (
Geschreven voor
- Instelling
- Harvard University
- Vak
- CS50
Documentinformatie
- Geüpload op
- 26 mei 2024
- Aantal pagina's
- 5
- Geschreven in
- 2023/2024
- Type
- Tentamen (uitwerkingen)
- Bevat
- Vragen en antwoorden
Onderwerpen
-
cs50
-
cits2401 written exam questions correctly answered