Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6209065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:55:04+00:00 2026-05-24T05:55:04+00:00

I have written following script in python which works fine: from sys import argv

  • 0

I have written following script in python which works fine:

from sys import argv

script, filename = argv

def brokerage(cost):
    vol = 100
    tamt = cost*vol
    br = (((cost*0.1)/100)*vol)*2
    rc = (0.0074*tamt)/100
    stt = (0.025*tamt)/100
    std = (0.004*tamt)/100
    stb = (11*br)/100
    tbr = br+rc+stt+std+stb
    return(tbr)

cost1 = 10
cost2 = 510

while cost1 < 501 and cost2 < 1001:
    value1 = brokerage(cost1)
    value2 = brokerage(cost2)
    # Can't write 'float' to file so, changed it into string. Don't know why.
    x1 = str(value1)
    x2 = str(value2)
    line = "  |%d\t\t%s\t|\t|%d\t\t%s\t|" % (cost1, x1, cost2, x2)
    # use 'a' in 'open' function to append it, will not overwrite existing value
    # as with 'w'.
    save = open(filename, 'a')
    save.write(line)
    save.write("\n  |---------------------|\t|-----------------------|\n")
    save.close
    cost1+=10
    cost2+=10

Now instead of “while” I want to use “for” with minimal code structure change.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:55:05+00:00Added an answer on May 24, 2026 at 5:55 am
    for cost1,cost2 in zip(range(10,501,10),range(510,1001,10)):
        # your code
    

    or faster:

    for cost1 in range(10,501,10):
        cost2 = cost1 + 500
        # Your code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a KornShell (ksh) script that sets an array the following way:
I have written a ruby script which opens up dlink admin page in firefox
I have written a python script to use gstreamer (pygst and gst modules) to
I have written the following script below - I am not quite happy with
I have written the following contact form validation script. How can I validate a
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have written something that uses the following includes: #include <math.h> #include <time.h> #include
I have the following in a program (written in VB.NET): Imports Microsoft.Office.Interop.Excel Public Class
(All of the following is to be written in Java) I have to build
I have written an AIR Application that downloads videos and documents from a server.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.