How to merge two codes?How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How can I make a time delay in Python?How do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How do I list all files of a directory?
Trapping Rain Water
How to build suspense or so to establish and justify xenophobia of characters in the eyes of the reader?
How to tell your grandparent to not come to fetch you with their car?
What risks are there when you clear your cookies instead of logging off?
Which comes first? Multiple Imputation, Splitting into train/test, or Standardization/Normalization
Payment instructions allegedly from HomeAway look fishy to me
Should I compare a std::string to "string" or "string"s?
Genetic limitations to learn certain instruments
If you had a giant cutting disc 60 miles diameter and rotated it 1000 rps, would the edge be traveling faster than light?
How did they achieve the Gunslinger's shining eye effect in Westworld?
How do I write "Show, Don't Tell" as a person with Asperger Syndrome?
Find duplicated column value in CSV
What is the giant octopus in the torture chamber for?
What are the peak hours for public transportation in Paris?
Why doesn't Adrian Toomes give up Spider-Man's identity?
Scrum Master role: Reporting?
BGP multihome issue
Was the Tamarian language in "Darmok" inspired by Jack Vance's "The Asutra"?
What should the arbiter and what should have I done in this case?
Is the term 'open source' a trademark?
What's up with this leaf?
Why doesn’t a normal window produce an apparent rainbow?
How can I most clearly write a homebrew item that affects the ground below its radius after the initial explosion it creates?
Implement Homestuck's Catenative Doomsday Dice Cascader
How to merge two codes?
How to merge two dictionaries in a single expression?How do I check if a list is empty?How do I check whether a file exists without exceptions?How can I safely create a nested directory?How can I make a time delay in Python?How do I sort a dictionary by value?How to make a chain of function decorators?How to make a flat list out of list of listsHow do I concatenate two lists in Python?How do I list all files of a directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am new at programming and was working on this project where I had written a code that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other but I am facing a but of an issue.
These are my codes and I know they are separate but I want to merge them to print the patterns side by side.
integer=int(input("Enter an integer:"))
for i in range(integer):
for j in range(integer+integer):
print("*",end="")
print()
print("*"*integer)
for i in range(integer-2):
print("*"+" "*(integer-2)+"*")
print("*"*integer)
expected output:
***** *****
***** * *
***** * *
***** * *
***** *****
Actual output:
*****
*****
*****
*****
*****
*****
* *
* *
* *
*****
python python-3.x
add a comment |
I am new at programming and was working on this project where I had written a code that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other but I am facing a but of an issue.
These are my codes and I know they are separate but I want to merge them to print the patterns side by side.
integer=int(input("Enter an integer:"))
for i in range(integer):
for j in range(integer+integer):
print("*",end="")
print()
print("*"*integer)
for i in range(integer-2):
print("*"+" "*(integer-2)+"*")
print("*"*integer)
expected output:
***** *****
***** * *
***** * *
***** * *
***** *****
Actual output:
*****
*****
*****
*****
*****
*****
* *
* *
* *
*****
python python-3.x
Instead of usingprint
, save the strings in a list, combine, and only thenprint
them out. Think of aprint
statement as the final output on screen, and once you print something, it should already be in the form you need it to be.
– Paritosh Singh
Mar 24 at 16:19
add a comment |
I am new at programming and was working on this project where I had written a code that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other but I am facing a but of an issue.
These are my codes and I know they are separate but I want to merge them to print the patterns side by side.
integer=int(input("Enter an integer:"))
for i in range(integer):
for j in range(integer+integer):
print("*",end="")
print()
print("*"*integer)
for i in range(integer-2):
print("*"+" "*(integer-2)+"*")
print("*"*integer)
expected output:
***** *****
***** * *
***** * *
***** * *
***** *****
Actual output:
*****
*****
*****
*****
*****
*****
* *
* *
* *
*****
python python-3.x
I am new at programming and was working on this project where I had written a code that reads an integer and displays, using asterisks, a filled and hollow square, placed next to each other but I am facing a but of an issue.
These are my codes and I know they are separate but I want to merge them to print the patterns side by side.
integer=int(input("Enter an integer:"))
for i in range(integer):
for j in range(integer+integer):
print("*",end="")
print()
print("*"*integer)
for i in range(integer-2):
print("*"+" "*(integer-2)+"*")
print("*"*integer)
expected output:
***** *****
***** * *
***** * *
***** * *
***** *****
Actual output:
*****
*****
*****
*****
*****
*****
* *
* *
* *
*****
python python-3.x
python python-3.x
asked Mar 24 at 16:15
Abdul MoizAbdul Moiz
31
31
Instead of usingprint
, save the strings in a list, combine, and only thenprint
them out. Think of aprint
statement as the final output on screen, and once you print something, it should already be in the form you need it to be.
– Paritosh Singh
Mar 24 at 16:19
add a comment |
Instead of usingprint
, save the strings in a list, combine, and only thenprint
them out. Think of aprint
statement as the final output on screen, and once you print something, it should already be in the form you need it to be.
– Paritosh Singh
Mar 24 at 16:19
Instead of using
print
, save the strings in a list, combine, and only then print
them out. Think of a print
statement as the final output on screen, and once you print something, it should already be in the form you need it to be.– Paritosh Singh
Mar 24 at 16:19
Instead of using
print
, save the strings in a list, combine, and only then print
them out. Think of a print
statement as the final output on screen, and once you print something, it should already be in the form you need it to be.– Paritosh Singh
Mar 24 at 16:19
add a comment |
2 Answers
2
active
oldest
votes
Here you go.
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
Output:
Enter an integer: 5
***** *****
***** * *
***** * *
***** * *
***** *****
Alternatively, here is one much easier to understand:
integer=int(input("Enter an integer:"))
full = "*"*integer
cap = full + " " + full
hollow = "*" + " "*(integer-2) + "*"
print(cap)
for i in range(integer-2):
print(full + " " + hollow)
print(cap)
Produces identical output
add a comment |
This code works by separating the two unique lines:
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325836%2fhow-to-merge-two-codes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here you go.
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
Output:
Enter an integer: 5
***** *****
***** * *
***** * *
***** * *
***** *****
Alternatively, here is one much easier to understand:
integer=int(input("Enter an integer:"))
full = "*"*integer
cap = full + " " + full
hollow = "*" + " "*(integer-2) + "*"
print(cap)
for i in range(integer-2):
print(full + " " + hollow)
print(cap)
Produces identical output
add a comment |
Here you go.
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
Output:
Enter an integer: 5
***** *****
***** * *
***** * *
***** * *
***** *****
Alternatively, here is one much easier to understand:
integer=int(input("Enter an integer:"))
full = "*"*integer
cap = full + " " + full
hollow = "*" + " "*(integer-2) + "*"
print(cap)
for i in range(integer-2):
print(full + " " + hollow)
print(cap)
Produces identical output
add a comment |
Here you go.
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
Output:
Enter an integer: 5
***** *****
***** * *
***** * *
***** * *
***** *****
Alternatively, here is one much easier to understand:
integer=int(input("Enter an integer:"))
full = "*"*integer
cap = full + " " + full
hollow = "*" + " "*(integer-2) + "*"
print(cap)
for i in range(integer-2):
print(full + " " + hollow)
print(cap)
Produces identical output
Here you go.
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
Output:
Enter an integer: 5
***** *****
***** * *
***** * *
***** * *
***** *****
Alternatively, here is one much easier to understand:
integer=int(input("Enter an integer:"))
full = "*"*integer
cap = full + " " + full
hollow = "*" + " "*(integer-2) + "*"
print(cap)
for i in range(integer-2):
print(full + " " + hollow)
print(cap)
Produces identical output
edited Mar 24 at 16:35
answered Mar 24 at 16:21
PrinceOfCreationPrinceOfCreation
19611
19611
add a comment |
add a comment |
This code works by separating the two unique lines:
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
add a comment |
This code works by separating the two unique lines:
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
add a comment |
This code works by separating the two unique lines:
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
This code works by separating the two unique lines:
integer=int(input("Enter an integer:"))
print("*"*integer + " " + "*"*integer)
for i in range(integer-2):
print("*"*integer + " " + "*" + " "*(integer-2) + "*")
print("*"*integer + " " + "*"*integer)
answered Mar 24 at 16:21
Alec AlameddineAlec Alameddine
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325836%2fhow-to-merge-two-codes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Instead of using
print
, save the strings in a list, combine, and only thenprint
them out. Think of aprint
statement as the final output on screen, and once you print something, it should already be in the form you need it to be.– Paritosh Singh
Mar 24 at 16:19