Search Results

Search found 19539 results on 782 pages for 'pretty print'.

Page 152/782 | < Previous Page | 148 149 150 151 152 153 154 155 156 157 158 159  | Next Page >

  • Python 3: Recursivley find if number is even

    - by pythonhack
    I am writing a program that must find if a number is even or not. It needs to follow this template. I can get it to find if a number is even or not recursively (call function and subtract 2, base case zero), but I am having a hard time following this template, based on how the isEven function is called in the main function. Any help would be greatly appreciated. Write a recursive function called isEven that finds whether a number is even or not: def isEven() #recursivley determine whether number is even or not def main(): number=int(input(“Enter a number : “)) if (isEven(number)): print(“Number is even”) else: print(“Number is not even”) main() Thank you! Appreciate it.

    Read the article

  • Define new Drupal theme region inside a block

    - by oalo
    I have a footer block, and I need to print a block inside that block. So i have defined the new region inside my theme.info file, cleared caches, enabled PHP code input, and written this code inside the footer block: <div class="grid-4 suffix-4 omega"> <?php if ($footer-right): ?> <div id="footer-right"> <?php print $footer-right; ?> </div> </div> I have configured a block to appear inside the new region (which appears in the blocks admin page), but it doesnt show. Any idea about what may be happening? Thank you

    Read the article

  • Using methods on 2 input files - 2nd is printing multiple times - Java

    - by Aaa
    I have the following code to read in text, store in a hashmap as bigrams (with other methods to sort them by frequency and do v. v. basic additive smoothing. I had it working great for one language input file (english) and then I want to expand it for the second language input file (japanese - doens;t matter what it is I suppose) using the same methods but the Japanese bigram hashmap is printing out 3 times in a row with diff. values. I've tried using diff text in the input file, making sure there are no gaps in text etc. I've also put print statements at certain places in the Japanese part of the code to see if I can get any clues but all the print statements are printing each time so I can't work out if it is looping at a certain place. I have gone through it with a fine toothcomb but am obviously missing something and slowly going crazy here - any help would be appreciated. thanks in advance... package languagerecognition2; import java.lang.String; import java.io.InputStreamReader; import java.util.*; import java.util.Iterator; import java.util.List.*; import java.util.ArrayList; import java.util.AbstractMap.*; import java.lang.Object; import java.io.*; import java.util.Enumeration; import java.util.Arrays; import java.lang.Math; public class Main { /** public static void main(String[] args) { //training English ----------------------------------------------------------------- File file = new File("english1.txt"); StringBuffer contents = new StringBuffer(); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String test = null; //test = reader.readLine(); // repeat until all lines are read while ((test = reader.readLine()) != null) { test = test.toLowerCase(); char[] charArrayEng = test.toCharArray(); HashMap<String, Integer> hashMapEng = new HashMap<String, Integer>(bigrams(charArrayEng)); LinkedHashMap<String, Integer> sortedListEng = new LinkedHashMap<String, Integer>(sort(hashMapEng)); int sizeEng=sortedListEng.size(); System.out.println("Total count of English bigrams is " + sizeEng); LinkedHashMap<String, Integer> smoothedListEng = new LinkedHashMap<String, Integer>(smooth(sortedListEng, sizeEng)); //print linkedHashMap to check values Set set= smoothedListEng.entrySet(); Iterator iter = set.iterator ( ) ; System.out.println("Beginning English"); while ( iter.hasNext()) { Map.Entry entry = ( Map.Entry ) iter.next ( ) ; Object key = entry.getKey ( ) ; Object value = entry.getValue ( ) ; System.out.println( key+" : " + value); } System.out.println("End English"); }//end while }//end try catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader != null) { reader.close(); } } catch (IOException e) { e.printStackTrace(); } } //End training English----------------------------------------------------------- //Training japanese-------------------------------------------------------------- File file2 = new File("japanese1.txt"); StringBuffer contents2 = new StringBuffer(); BufferedReader reader2 = null; try { reader2 = new BufferedReader(new FileReader(file2)); String test2 = null; //repeat until all lines are read while ((test2 = reader2.readLine()) != null) { test2 = test2.toLowerCase(); char[] charArrayJap = test2.toCharArray(); HashMap<String, Integer> hashMapJap = new HashMap<String, Integer>(bigrams(charArrayJap)); //System.out.println( "bigrams stage"); LinkedHashMap<String, Integer> sortedListJap = new LinkedHashMap<String, Integer>(sort(hashMapJap)); //System.out.println( "sort stage"); int sizeJap=sortedListJap.size(); //System.out.println("Total count of Japanese bigrams is " + sizeJap); LinkedHashMap<String, Integer> smoothedListJap = new LinkedHashMap<String, Integer>(smooth(sortedListJap, sizeJap)); System.out.println( "smooth stage"); //print linkedHashMap to check values Set set2= smoothedListJap.entrySet(); Iterator iter2 = set2.iterator(); System.out.println("Beginning Japanese"); while ( iter2.hasNext()) { Map.Entry entry2 = ( Map.Entry ) iter2.next ( ) ; Object key = entry2.getKey ( ) ; Object value = entry2.getValue ( ) ; System.out.println( key+" : " + value); }//end while System.out.println("End Japanese"); }//end while }//end try catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader2 != null) { reader2.close(); } } catch (IOException e) { e.printStackTrace(); } } //end training Japanese--------------------------------------------------------- } //end main (inner)

    Read the article

  • How to test a regex password in Python?

    - by jCuga
    Using a regex in Python, how can I verify that a user's password is: At least 8 characters Must be restricted to, though does not specifically require any of: uppercase letters: A-Z lowercase letters: a-z numbers: 0-9 any of the special characters: @#$%^&+= Note, all the letter/number/special chars are optional. I only want to verify that the password is at least 8 chars in length and is restricted to a letter/number/special char. It's up to the user to pick a stronger / weaker password if they so choose. So far what I have is: import re pattern = "^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$" password = raw_input("Enter string to test: ") result = re.findall(pattern, password) if (result): print "Valid password" else: print "Password not valid"

    Read the article

  • Selenium selected option in dropdown not displayed correctly

    - by luckyfool
    I have the following issue with Selenium Webdriver. There are two dropdown menus on a page i am testing "brand" and "items". The options of "items" depend on which brand you choose. I am trying to iterate through all possible choices and print brand-item pairs. I use two possible ways to pick an option from each dropdown menu Using Select(): def retryingSelectOption(name,n): result=False attempts=0 while attempts<5: try: element=Select(driver.find_element_by_name(name)) element.select_by_index(n) print element.all_selected_options[0].text result=True break except StaleElementReferenceException: pass attempts+=1 return result And using .click(): def retryingClickOption(name,n): result=False attempts=0 while attempts<5: try: driver.find_element_by_name(name).find_elements_by_tag_name("option")[n].click() result=True break except StaleElementReferenceException: pass attempts+=1 return result My problem is that at ,what seem to me as random moments (sometimes it works sometimes it does not), even though the above functions return True and printing out the selected option shows me the correct answer, the browser still displays the previous option. So basically Selenium tells me i have picked the right option but the browser displays the previous one.No idea what is wrong.

    Read the article

  • set arraylist element as null

    - by Jessy
    The first index is set to null (empty), but it doesn't print the right output, why? //set the first index as null and the rest as "High" String a []= {null,"High","High","High","High","High"}; //add array to arraylist ArrayList<Object> choice = new ArrayList<Object>(Arrays.asList(a)); for(int i=0; i<choice.size(); i++){ if(i==0){ if(choice.get(0).equals(null)) System.out.println("I am empty"); //it doesn't print this output } }

    Read the article

  • how could it works if function is called before it is defined in python?

    - by user2131316
    I was wondering what does if __name__ == "__main__": really do in python, I have the following code in python3: def main(): test(); def test(): print("hello world " + __name__); if __name__ == "__main__": main(); we know that we have to declare a function before we use it, so function call inside of if part works fine, the main() is defined before it is called inside of if statement, but what about the test() function, it is defined after it is called and there is no errors: def main(): test(); def test(): print("hello world " + __name__); so how could it works if the test() function is defined after it is called?

    Read the article

  • C++ new line not translating

    - by m3n
    First off, I'm a complete beginner at C++. I'm coding something using an API, and would like to pass text containing new lines to it, and have it print out the new lines at the other end. If I hardcode whatever I want it to print out, like so printInApp("Hello\nWorld"); it does come out as separate lines in the other end, but if I retrieve the text from the app using a method that returns a const char then pass it straight to printInApp (which takes const char as argument), it comes out as a single line. Why's this and how would I go about to fix it?

    Read the article

  • How suitable is a DVCS for the corporate environment?

    - by Matt Brailsford
    I've been using SVN for some time now, and am pretty happy with how it works (but I can't say I'm an expert, and I haven't really done much with branches and merging). However an opportunity has arisen to put in some new practises on a new team and so I thought I'd take a look at DVCSs to see if it's worth making the jump. The company I work for is a pretty standard company where we all work in the same location (or sometimes at home) and we want to keep a central store of all code. My question is: if all you are doing with a DVCS is creating a central hub that everyone pushes their changes to, is there really any benefit to moving to a DVCS and its extra overheads in this sort of environment?

    Read the article

  • Wait until a webpage finished loading to load the next one in a list

    - by envy
    Hi! I'm using PyQT webView to visit some webpages I have stored on a dictionary the code is something like this: def loadLink(self, url): manager = QNetworkAccessManager() request = QNetworkRequest(QUrl(url)) self.ui.webView.load(QUrl(visitar)) def readUnreadLinks(self): print "Links to read: " + str(len(self.unreadLinks)) for link in self.unreadLinks: print "link-> " + str(link) self.loadLink(link) the problem is it doesn't wait until finished loading the web page and starts loading the next one. I want to load a webpage, wait until it finished loading and then load the next one. Thanks, this is driving me crazy :)

    Read the article

  • different behavior when using re.finditer and re.match.

    - by Shahzad
    Hi, I'm working on a regex to to collect some values from a page through some script. I'm using re.match in condition but it returns false but if i use finditer it returns true and body of condition is executed. i tested that regex in my own built tester and it's working there but not in script. here is sample script. result = [] RE_Add0 = re.compile("\d{5}(?:(?:-| |)\d{4})?", re.IGNORECASE) each = ''Expiration Date:\n05/31/1996\nBusiness Address: 23901 CALABASAS ROAD #2000 CALABASAS, CA 91302\n' if RE_Add0.match(each): result0 = RE_Add0.match(each).group(0) print result0 if len(result0) < 100: result.append(result0) else: print 'Address ignore' else: None

    Read the article

  • How to Replace only Part of the Variable using #define

    - by mahesh
    #define C_TX_ TX_ #define C_RX_ RX_ enum Test { C_TX_MAC 0x0100, // Pre-Processor should replace C_TX_ to TX_ C_RX_MAC 0x0101 // But Not Working. }; int main(int argc, char *argv[]) { cout << TX_MAC; // HOW TO PRINT ? cout << RX_MAC; // HOW TO PRINT ? return true; } Please Help. Thanks in Advance

    Read the article

  • How can I evaluate variable to another variable before assigning?

    - by HH
    #!/usr/bin/python # # Description: trying to evaluate array -value to variable before assignment # but it overwrites the variable # # How can I evaluate before assigning on the line 16? #Initialization, dummy code? x=0 y=0 variables = [x, y] data = ['2,3,4', '5,5,6'] # variables[0] should be evaluted to `x` here, i.e. x = data[0], how? variables[0] = data[0] if ( variables[0] != x ): print("It does not work, why?"); else: print("It works!");

    Read the article

  • Does template class/function specialization improves compilation/linker speed?

    - by Stormenet
    Suppose the following template class is heavily used in a project with mostly int as typename and linker speed is noticeably slower since the introduction of this class. template <typename T> class MyClass { void Print() { std::cout << m_tValue << std::endl;; } T m_tValue; } Will defining a class specialization benefit compilation speed? eg. void MyClass<int>::Print() { std::cout << m_tValue << std::endl; }

    Read the article

  • Array Related Doubt.......

    - by AGeek
    I have the following program........... int insert(int *array, int arraySize, int newElement) { array[arraySize + 1] = newElement; return (arraySize+1); // Return new Array size...... } int main() { int array[] = {1,2,3,4,5}; int arraySize = sizeof(array) / sizeof(int); insertInArray(array, arraySize,6); print(array); } I am trying to work out this program in C programming language... But when i print the array after insertion,,, it doesn't prints the desired output which is needed.. Please correct me if i am doing something wrong..... Thanks..

    Read the article

  • SSRS 2008 Report.GetDefaultPageSettings returns incorrect information

    - by jhale
    I have an application that retrieves a report from SSRS 2008 and prints it automatically. This works except it always prints the report in Letter/Portrait. This particular report is Letter/Landscape. I have tracked the problem down to when calling the Report.GetDefaultPageSettings() function for this report, it returns PaperSize.Height = 1100 and PaperSize.Width = 850. I even modified the report to a custom size of 11" x 8.4" and it still returns 850 for the width. I cannot get this to print correctly when it renders the image incorrectly based on these settings. The report prints correctly when accessed by a web browser. It is only when I am trying to automatically print it that the issue appears.

    Read the article

  • Why is Rake not able to invoke multiple tasks consecutively?

    - by PandaWood
    I have a Rake task which I have simplified below. I'm using Ruby 1.9 on Windows. Perhaps you would like to guess the outcome of calling the Rake task "list_all_levels" below? It should be: "Hello level 1" "Hello level 2" "Hello level 3" But for reasons unknown to me, it prints only "Hello level 1" and then stops. That is, it always invokes only the first task. If I change the first line to pass the arg "42", it would print "Hello level 42" and then stop. I'm wondering why does it not invoke the task 3 times and print all 3 lines? And is there any way to get it to work how I would expect? task :list_all_levels => [] do Rake::Task[:list].invoke 1 Rake::Task[:list].invoke 2 Rake::Task[:list].invoke 3 end task :list, [:level] => [] do |t, args| puts "Hello level #{args.level}" end

    Read the article

  • How can I initialize a 2d array in Perl?

    - by Mark
    How do I initialize a 2d array in perl? I am trying the following code: 0 use strict; 10 my @frame_events = (((1) x 10), ((1) x 10)); 20 print "$frame_events[1][1]\n"; but it gives the following error: Can't use string ("1") as an ARRAY ref while "strict refs" in use at ./dyn_pf.pl line 20. This syntax only seems to initialize a 1d array as print "$frame_events[1]\n" works. Though perl doesn't give any error during the assignment.

    Read the article

  • linux cpu usage

    - by davidbobo
    I am working on unix. I want to knwo the current cpu usage of a process. I understood that ps give the average of cpu used till the process is up - it is not the current usage. Is there a way to print only the cpu from the top command without 10 more parameters and headers? I know how to do it with awk - this is not the way i want to do it. top -p 20705 -bc -n 1 | tail -n 2 | awk '{ print $9}' | head -n 1 If there is another simple way to do it, not reading /proc/stat... If there is a simple way doing it from c++, it is also ok.

    Read the article

  • What's the best approach to printing/reporting from WPF?

    - by Matt Hamilton
    I have an upcoming project which will have to be able to print simple reports from its data. It'll be WPF-based, and I'm wondering which way to go. I know that WPF introduces its own printing technology (based on XPS) which looks quite easy to use. However, part of me wonders whether it would just be easier to use the ReportViewer control and embed it in a Windows Forms host control, since that will give users the ability to export to a variety of formats as well as print. Has anyone had any experience with printing/reporting from WPF? Which direction would you recommend?

    Read the article

  • How do I split Chinese characters one by one?

    - by Nano HE
    If there is no special character(such as white space, : etc) between firstname and lastname. Then how to split the Chinese characters below. use strict; use warnings; use Data::Dumper; my $fh = \*DATA; my $fname; # ??; my $lname; # ? ; while(my $name = <$fh>) { $name =~ ??? ; print $fname"/n"; print $lname; } __DATA__ ??? Output ?? ?

    Read the article

  • Removing Item From List - during iteration - what's wrong with this idiom ?

    - by monojohnny
    As an experiment, I did this: letters=['a','b','c','d','e','f','g','h','i','j','k','l'] for i in letters: letters.remove(i) print letters The last print shows that not all items were removed ? (every other was). IDLE 2.6.2 >>> ================================ RESTART ================================ >>> ['b', 'd', 'f', 'h', 'j', 'l'] >>> What's the explanation for this ? How it could this be re-written to remove every item ?

    Read the article

  • Compilation Error related

    - by aparna
    Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +", "); 15. } else { 16. System.out.print(str.charAt(0) + ", "); 17. } 18. } and the invocation: 21. test("four"); 22. test("tee"); 23. test("to"); What is the result? A. r, t, t, B. r, e, o, C. Compilation fails. D. An exception is thrown at runtime. Answer: C Can you explain why the compilation fails please?

    Read the article

  • R Plot Specify number of time tickmarks

    - by Cookie
    I was wondering how I could plot more tick marks when plotting time on the x-axis. Basically, a time equivalent to pretty. Pretty obviously doesn't work so well with times, as it uses factors of 1,2,5 and 10. For time one probably wants e.g. hours, half hours, ... plot(as.POSIXct(x,origin="1960-01-01"),y,type="l",xlab="Time") gives really too few and widely spaced tickmarks. zoox<-zoo(y,as.POSIXct(stats$Time,origin="1960-01-01")) plot(zoox) gives the same. Thanks

    Read the article

< Previous Page | 148 149 150 151 152 153 154 155 156 157 158 159  | Next Page >