Displaying the first letter of each word in a single variable [on hold]
$begingroup$
I have a variable with two words, and I am confused on how to display the first letter of each word.
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice(var1, var2)
print(var3[0])
So how would I display the first letter of either variable, seeing as both words have different lengths?
python beginner python-3.x
$endgroup$
put on hold as off-topic by πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have a variable with two words, and I am confused on how to display the first letter of each word.
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice(var1, var2)
print(var3[0])
So how would I display the first letter of either variable, seeing as both words have different lengths?
python beginner python-3.x
$endgroup$
put on hold as off-topic by πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
$begingroup$
I have a variable with two words, and I am confused on how to display the first letter of each word.
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice(var1, var2)
print(var3[0])
So how would I display the first letter of either variable, seeing as both words have different lengths?
python beginner python-3.x
$endgroup$
I have a variable with two words, and I am confused on how to display the first letter of each word.
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice(var1, var2)
print(var3[0])
So how would I display the first letter of either variable, seeing as both words have different lengths?
python beginner python-3.x
python beginner python-3.x
asked 16 hours ago
Ali RakhadaAli Rakhada
1
1
put on hold as off-topic by πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250 13 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, 200_success, Ludisposed, Toby Speight, Hosch250
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Try this:
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice( var1[0] + var2[0] )
print( var3 )
The output will be either D
for Donkey Kong
or K
for King Bowser
.
This is because var1[0] + var2[0]
essentially becomes a new string: DK
.
That's the first characters [0]
of both strings var1
and var2
.
You can check it with: print( var1[0] + var2[0] )
.
$endgroup$
1
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Try this:
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice( var1[0] + var2[0] )
print( var3 )
The output will be either D
for Donkey Kong
or K
for King Bowser
.
This is because var1[0] + var2[0]
essentially becomes a new string: DK
.
That's the first characters [0]
of both strings var1
and var2
.
You can check it with: print( var1[0] + var2[0] )
.
$endgroup$
1
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
add a comment |
$begingroup$
Try this:
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice( var1[0] + var2[0] )
print( var3 )
The output will be either D
for Donkey Kong
or K
for King Bowser
.
This is because var1[0] + var2[0]
essentially becomes a new string: DK
.
That's the first characters [0]
of both strings var1
and var2
.
You can check it with: print( var1[0] + var2[0] )
.
$endgroup$
1
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
add a comment |
$begingroup$
Try this:
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice( var1[0] + var2[0] )
print( var3 )
The output will be either D
for Donkey Kong
or K
for King Bowser
.
This is because var1[0] + var2[0]
essentially becomes a new string: DK
.
That's the first characters [0]
of both strings var1
and var2
.
You can check it with: print( var1[0] + var2[0] )
.
$endgroup$
Try this:
import random
var1 = "Donkey Kong"
var2 = "King Bowser"
var3 = random.choice( var1[0] + var2[0] )
print( var3 )
The output will be either D
for Donkey Kong
or K
for King Bowser
.
This is because var1[0] + var2[0]
essentially becomes a new string: DK
.
That's the first characters [0]
of both strings var1
and var2
.
You can check it with: print( var1[0] + var2[0] )
.
answered 14 hours ago
tjt263tjt263
32437
32437
1
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
add a comment |
1
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
1
1
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
$begingroup$
You should refrain from awnsering off topic questions.
$endgroup$
– Ludisposed
9 hours ago
add a comment |