Practice: Python Basic Data Types
Contents
4.5.2. Practice: Python Basic Data Types#
Greeting#
Make a new variable called greeting_part_1
and assign it the string: "Welcome, "
Note: There is an extra space after the word
# TODO: enter your code here
Make a new variable called greeting_part_2
and assign it the string: "! It is nice to meet you!"
Note: this string starts with an exlamation mark.
# TODO: enter your code here
Make a variable called name_1 and assign it with a string of someone’s name.
# TODO: enter your code here
Now, combine them all together into a new variable called full_greeting
. Combine the parts together by taking greeting_part_1
then adding name
then adding greeting_part_2
.
Then display the variable full_greeting
.
# TODO: enter your code here
Now make a variable called name_2
with another name in it and make a variable called_full_greeting_2
the same way you did full_greeting
, but with name_2
instead.
Then display the variable full_greeting_2
# TODO: enter your code here
Engagement report#
Make up numbers for tweet metrics and save them into variables: number_likes
, number_retweets
, number_quote_tweets
# TODO: enter your code here
Write three different display()
function calls, one to report on each of those variables.
Inside the parentheses first put a string like, "The number of likes is: "
and then add the relevant variable to it, but remember, since the variable has a number in it, you have to put a str()
function call around that variable name
# TODO: enter your code here
Make a new variable called total_engagement
and save the total number of all the likes, retweets and quote tweets.
Then display that information the way you did the other variables.
# TODO: enter your code here
Is your tweet too long#
Make a variable called tweet_1
with a string of your choosing that is fairly short
# TODO: enter your code here
Make a variable called tweet_1_length
, and save the length of the string tweet_1
into it (using the len()
function)
# TODO: enter your code here
Check if the tweet_1_length
is less than or equal to 280 characters (the max length of a tweet) using the less than or equal operator: <=
, and save the result into a variable called is_tweet_1_short_enough
# TODO: enter your code here
Use the display()
function to display a string ("Is tweet 1 short enough? "
), adding the variable is_tweet_1_short_enough
to that string.
Remember, since the variable has a boolean and not a string in it, you have to put a str() function call around that variable name
# TODO: enter your code here
Make a variable called tweet_2
with a string of your choosing that is very long (over 280 characters)
# TODO: enter your code here
Repeat the rest of the steps from before, but with tweet_2
find tweet_2_length
make a variable is_tweet_2_short_enough
display the result
# TODO: enter your code here