Displaying the first letter of each word in a single variable [on hold]












-2












$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?










share|improve this question









$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.


















    -2












    $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?










    share|improve this question









    $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.
















      -2












      -2








      -2


      0



      $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?










      share|improve this question









      $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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      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.






















          1 Answer
          1






          active

          oldest

          votes


















          -1












          $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] ).






          share|improve this answer









          $endgroup$









          • 1




            $begingroup$
            You should refrain from awnsering off topic questions.
            $endgroup$
            – Ludisposed
            9 hours ago


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          -1












          $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] ).






          share|improve this answer









          $endgroup$









          • 1




            $begingroup$
            You should refrain from awnsering off topic questions.
            $endgroup$
            – Ludisposed
            9 hours ago
















          -1












          $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] ).






          share|improve this answer









          $endgroup$









          • 1




            $begingroup$
            You should refrain from awnsering off topic questions.
            $endgroup$
            – Ludisposed
            9 hours ago














          -1












          -1








          -1





          $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] ).






          share|improve this answer









          $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] ).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 14 hours ago









          tjt263tjt263

          32437




          32437








          • 1




            $begingroup$
            You should refrain from awnsering off topic questions.
            $endgroup$
            – Ludisposed
            9 hours ago














          • 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



          Popular posts from this blog

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар